#include #include struct List { int value; struct List *next; }; void print(struct List *h); struct List *makeList( ); /* ==================================================== 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 // **** **** You MUST free(h) in C !!! ********* } else return NULL; } void main( ) { struct List *head = makeList( ); // Make an list for demo print(head); /* ------------------------------------------------- Delete the first list element from list at head ------------------------------------------------- */ head = delete(head); // Delete first elem in head print(head); /* ------------------------------------------------------- Delete the first list element from list at head AGAIN ------------------------------------------------------- */ head = delete(head); // Delete first elem in head print(head); } // Make a list struct List *makeList( ) { struct List *h = NULL; struct List *p; for ( int i = 1; i <= 5; i++ ) { p = malloc( sizeof( struct List) ); p->value = i; p->next = h; h = p; } return h; } // Print the list void print(struct List *h) { while (h != NULL) { printf("%d ", h->value); h = h->next; } printf("\n\n"); }