/* hw2.c - Linked list exercises from Standish text, pp. 53-54. Test program for part 2 of CS 12 assignment 2, Fall 2008. DO NOT RELY ON CHANGES TO THIS FILE - you will not turn it in. updated by cmc, 10/9/08 */ #include #include #include #include "airports.h" /* main - tests the exercise functions */ int main(int argc, char *argv[]) { NodeType *list1, *list2, *list3, *m, *n; list1 = list2 = list3 = NULL; /* use append to create list1 and print it */ append("DUS", &list1); append("ORD", &list1); append("SAN", &list1); printf("list1 - created by 3 appends: "); printList(list1); /* use insertFirst to create list2 and print it */ insertFirst("LAX", &list2); insertFirst("DFW", &list2); insertFirst("JFK", &list2); printf("list2 - created by 3 insertFirsts: "); printList(list2); /* test deleteFirst, and print revised list */ deleteFirst(&list1); printf("list1 after delete first: "); printList(list1); /* test insertNodeBeforeOther twice, and print revised list */ m = createNode("BRU"); n = list1->link; /* inserting BRU before SAN */ insertNodeBeforeOther(m, n); m = createNode("ZRH"); n = list1->link; insertNodeBeforeOther(m, n); /* now inserting ZRH before BRU */ printf("list1 after insert ZRH and BRU before SAN: "); printList(list1); /* test copy, and print the copy */ list3 = copy(list1); printf("list3 - copy of list1: "); printList(list3); /* clear the copy, and print both it and the original */ clearList(&list3); printf("list3 after clear: "); printList(list3); printf("list1 after list3 is cleared: "); printList(list1); /* test concat, and print the concatenated list */ list3 = concat(list1, list2); printf("new list 3 - concatenated list1, list2: "); printList(list3); /* test reverse, and print all lists */ reverse(&list3); printf("list3 after reverse: "); printList(list3); printf("list1 after list3 reversed: "); printList(list1); printf("list2 after list3 reversed: "); printList(list2); /* try some empty list operations - hope for no segmentation faults */ clearList(&list3); deleteFirst(&list3); reverse(&list3); list2 = copy(list3); list1 = concat(list2, list3); printf("should be an empty list: "); printList(list1); return 0; }