#include #include struct List { int value; struct List *next; }; /* ========================================= insert(h, e): insert e at start of list h return new list ========================================= */ struct List *insert (struct List *h, struct List *e) { e->next = h; return e; // Return new list that starts at e } void print(struct List *h); // We must declare print to avoid compile error void main(int argc, char *argv[]) { struct List *head = NULL; // Empty list struct List *p; /* ------------------------------------------------- Create a list element and insert in List at head ------------------------------------------------- */ p = malloc( sizeof(struct List) ); p->value = 1; head = insert(head, p); // Insert p in head print(head); /* ------------------------------------------------- Create a list element and insert in List at head ------------------------------------------------- */ p = malloc( sizeof(struct List) ); p->value = 2; head = insert(head, p); // Insert p in head print(head); } // Print the list void print(struct List *h) { while (h != NULL) { printf("%d ", h->value); h = h->next; } printf("\n\n"); }