// // Run as: (ulimit -v 50000; a.out > err) // #include #include struct List { int value; struct List *next; }; void print(struct List *h); // Declaration struct List *insert (struct List *h, struct List *e); /* ==================================================== delete(h): delete the first elem from the list h return new list ==================================================== */ struct List *delete (struct List *h) { struct List *newHead; if ( h != NULL) { return h->next; // Not so fast in C... ! } else return NULL; } int main(int argc, char *argv[]) { struct List *head = NULL; int c = 0; while(1) { printf("%d\n", ++c); // Keep a count // Insert for (int i = 1; i <= 10; i++) { struct List *e = malloc( sizeof(struct List) ) ; e->value = i; head = insert(head, e); // Insert i at head print(head); } // Delete for (int i = 1; i <= 10; i++) { head = delete(head); // Delete at head print(head); } } } // Insert at head struct List *insert (struct List *h, struct List *e) { e->next = h; return e; // Return new list that starts at e } // Print the list void print(struct List *h) { while (h != NULL) { printf("%d ", h->value); h = h->next; } printf("\n"); }