/* This program uses code from "Algorithms in C, Third Edition," * by Robert Sedgewick, Addison-Wesley, 1998. */ #include #include #include "list_interface.h" list randomIntegers(int size, int limit) { list result = newList(); link current = listFirst(result); int i; for (i = 0; i < size; i++) { int value = rand() % limit; link new_item = newLink(value); insertLink(result, current, new_item); current = new_item; } return result; } main() { srand(time(NULL)); list list1 = randomIntegers(10, 1000); printf("printing list1:"); printList(list1); list list2 = randomIntegers(10, 1000); printf("printing list2:"); printList(list2); list merged = mergeLists(list1, list2); printf("printing merged list:"); printList(merged); printf("printing list1 after non-destructive merging:"); printList(list1); printf("printing list2: after non-destructive merging:"); printList(list2); mergeListsDestructive(list1, list2); printf("printing list1 after destructive merging:"); printList(list1); printf("printing list2: after destructive merging:"); printList(list2); destroyList(list1); free(list2); destroyList(merged); return 0; }