//stackTest.c //Author: John T. Rine //Date: October 12, 2011 #include"all.h" int main(int argc, char **argv) { int i, data; node *head, *tail, *temp, *copyHead, *copyTail; head = tail = temp = copyHead = copyTail = NULL; printf("Head is = 0x%x; Tail is = 0x%x\n", head, tail); printf("\nCreating a fixed size stack of 10 nodes...\n"); createFixedStack(&head, &tail, 10); printf("\nHead is = 0x%x; Tail is = 0x%x\n", head, tail); printf("\nSize of the list is: %d\n", listStackSizeTail(tail)); i = 10; temp = tail; while(temp != NULL) { temp->data = i; i--; temp = temp->prev; //temp = stack pointer } printf("\nPeeking at data in tail...\n"); printf("\nThe value in top of stack is %d\n", peek(tail)); if(isEmpty(tail)) printf("\nStack is empty!\n"); else printf("\nStack is not empty!\n"); temp = tail; while(temp != NULL) { printf("\nThis node contains %d\n", temp->data); temp = temp->prev; } printf("\nMaking a copy of the stack...\n"); copyStack(head, ©Head, ©Tail); printf("\nDestroying the first Stack...\n"); destroyFixedStackTail(&head, &tail); if(isEmpty(tail)) printf("\nStack is empty!\n"); else printf("\nStack is not empty!\n"); printf("\nHead is = 0x%x; Tail is = 0x%x\n", head, tail); printf("\nPrinting values of copy of stack...\n"); temp = copyTail; while(temp != NULL) { printf("\nThis node contains %d\n", temp->data); temp = temp->prev; } if(isEmpty(copyTail)) printf("\nCopy of stack is empty!\n"); else printf("\nCopy of stack is not empty!\n"); printf("\nDestroying copy of the stack...\n"); destroyFixedStackTail(©Head, ©Tail); if(isEmpty(copyTail)) printf("\nCopy of stack is empty!\n"); else printf("\nCopy of stack is not empty!\n"); printf("\nStarting a new stack using push and a loop...\n"); printf("\nEnter the number of data to push onto the stack...\n"); scanf("%d", &i); head = tail = NULL; for(;i > 0; i--) { printf("\nEnter the value to be pushed onto the stack...\n"); scanf("%d", &data); push(&head, &tail, data); } printf("\nHead is = 0x%x; Tail is = 0x%x\n", head, tail); printf("\nThe size of the stack is: %d\n", listStackSizeTail(tail)); printf("\nEnter the number of data to be popped off of the stack...\n"); scanf("%d", &i); for (;i > 0; i--) { printf("The value being popped off of the stack is %d\n", pop(&head, &tail)); } printf("\nHead is = 0x%x; Tail is = 0x%x\n", head, tail); printf("\nThe size of the stack is: %d\n", listStackSizeTail(tail)); getchar(); }