main.c (1058B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 struct lnode { 5 int value; 6 struct lnode *next; 7 }; 8 9 struct list { 10 struct lnode *head; 11 struct lnode *tail; 12 }; 13 14 int main() 15 { 16 void list_add(); 17 void list_dump(); 18 struct lnode * list_find(); 19 20 struct list mylist; 21 struct lnode * mynode; 22 23 mylist.head = NULL; 24 mylist.tail = NULL; 25 26 list_add(&mylist, 10); 27 list_add(&mylist, 20); 28 list_add(&mylist, 30); 29 list_dump(&mylist); 30 31 mynode = list_find(&mylist, 42); 32 if ( mynode == NULL ) { 33 printf("Did not find 42\n"); 34 } else { 35 printf("Looked for 42, found %d\n", mynode->value); 36 } 37 38 mynode = list_find(&mylist, 30); 39 if ( mynode == NULL || mynode->value != 30) { 40 printf("Did not find 30\n"); 41 } else { 42 printf("Found 30\n"); 43 } 44 45 list_add(&mylist, 40); 46 list_dump(&mylist); 47 48 } 49 50 void list_dump(lst) 51 struct list *lst; 52 { 53 struct lnode *cur; 54 printf("\nDump:\n"); 55 for(cur=lst->head; cur != NULL; cur=cur->next) { 56 printf(" %d\n", cur->value); 57 } 58 }