/* This program uses code from "Algorithms in C, Third Edition," * by Robert Sedgewick, Addison-Wesley, 1998. */ #include #include typedef struct node * link; struct node { int item; link next; }; /* Creates a new link, that contains the value * specified in the argument, * and that points to NULL. */ link newLink(int value) { link result = malloc(sizeof(struct node)); result->item = value; result->next = NULL; } void printList(link my_list) { printf("\n"); int counter = 0; link current_link; for (current_link = my_list; current_link != 0; current_link = current_link->next) { printf("item %d: %d\n", counter, current_link->item); counter++; } } main() { link the_list = newLink(573); the_list->next = newLink(100); the_list->next->next = newLink(200); printList(the_list); return 0; }