/* File: main1.c Using a simple linked list ADT to keep track of groceries */ #include #include "list1d.h" main() { list DinnerL, BabyL, ShoppingL ; list TempL1, TempL2 ; node *position ; printf("Make new dinner list\n") ; DinnerL = CreateList() ; PrintList(DinnerL) ; printf("\nAdd spaghetti & sauce to list\n") ; Append(DinnerL, "Spaghetti") ; PrintList(DinnerL) ; Append(DinnerL, "Sauce") ; PrintList(DinnerL) ; printf("\nAdd bread\n") ; Append(DinnerL, "Bread") ; PrintList(DinnerL) ; printf("\nAdd ground beef for meatballs\n") ; Append(DinnerL, "Beef") ; PrintList(DinnerL) ; printf("\nDon't forget the garlic!\n") ; Prepend(DinnerL, "Garlic") ; PrintList(DinnerL) ; printf("\nMake baby list\n") ; BabyL = CreateList() ; Prepend(BabyL, "Pampers #3") ; Append(BabyL, "Wipes") ; Prepend(BabyL, "Applesauce") ; Append(BabyL, "Peaches") ; PrintList(BabyL) ; printf("\nCopy and join lists\n") ; TempL1 = ListDup(BabyL) ; TempL2 = ListDup(DinnerL) ; Concatenate(TempL1, TempL2) ; ShoppingL = TempL1 ; printf("ShoppingL: ") ; PrintList(ShoppingL) ; printf("BabyL: ") ; PrintList(BabyL) ; printf("DinnerL: ") ; PrintList(DinnerL) ; FreeList(BabyL) ; FreeList(DinnerL) ; printf("\nRemove garlic\n") ; position = Locate(ShoppingL, "Garlic") ; Delete(ShoppingL, position) ; PrintList(ShoppingL) ; printf("\nGone Shopping... sauce & parmesan are on sale... buy some?\n") ; if (IsMember(ShoppingL, "Sauce")) { printf(" we need sauce\n") ; } else { printf(" we don't need sauce\n") ; } if (IsMember(ShoppingL, "Parmesan")) { printf(" we need parmesan\n") ; } else { printf(" we don't need parmesan\n") ; } printf("\nSome stats\n") ; printf("First Item: %s\n", FirstItem(ShoppingL) ) ; printf("Last Item: %s\n", LastItem(ShoppingL) ) ; printf("# of items: %d\n", CountList(ShoppingL) ) ; }