#include #include struct List // I want to use 1 prgram file for this example { int value; struct List *next; }; struct List *insert( struct List *head, struct List *e ); void print(struct List *h); struct List *delete (struct List *h); int main(int argc, char *argv[]) { struct List* head = NULL; // Empty list struct List *p; /* ------------------------------------------------- Create a list element and insert in List at head ------------------------------------------------- */ while(1) { for( int i=1; i <= 10; i++ ) { p = malloc( sizeof( struct List ) ); p->value = i; head = insert(head, p); // Insert p in head print(head); } for ( int i = 0; i < 10; i++ ) { head = delete(head); // Delete first element print(head); } } } /* ========================================= insert(h, e): insert e at tail of list h return new list A List variable is a reference variable !!! ========================================= */ struct List *insert( struct List* head, struct List *e ) { /* -------------------------------------------- Base case: insert at the tail of an empty -------------------------------------------- */ if ( head == NULL ) { e->next = NULL; // Mark e as the last list elem return(e); // e is the first list elem ! } else { /* =========================================================== Solve the problem USING the solution of a smaller problem =========================================================== */ head->next = insert( head->next, e ); // Link directly to helpSol return head; // Return MY solution } } /* ==================================================== delete(h): delete the first elem from the list h return new list ==================================================== */ struct List *delete (struct List *h) { if ( h != NULL ) { struct List *help = h->next; free(h); return (help); // Return new list that starts at h.next } else // deleting from empty list returns an empty list return NULL; } // Print the list void print(struct List *h) { while (h != NULL) { printf("%d ", h->value); h = h->next; } printf("\n"); }