/* * ISA 563, Spring 2011 * Copyleft by Muhammad Abdulla */ #include #include #include "stack3.h" #define MAXLINE 32 int main ( int argc, char *argv[] ) { int i; char line[MAXLINE]; fprintf(stdout, "Please enter numbers to stacked:\n"); Stack stack1; Stack stack2; Stack *s1 = &stack1; Stack *s2 = &stack2; stack_init(s1); stack_init(s2); // put some numbers into stack while ( fgets(line, sizeof(line), stdin) ) { i = atoi(line); if ( ! stack_full(s1) ) { stack_push(s1, i); } } // pop numbers, print them, and push them into another stack fprintf(stdout, "Numbers in reverse order:\n"); while ( ! stack_empty(s1) ) { i = stack_pop(s1); fprintf(stdout, "%d\n", i); if ( ! stack_full(s2) ) { stack_push(s2, i); } } // pop numbers from the second stack fprintf(stdout, "Numbers in original order:\n"); while ( ! stack_empty(s2) ) { i = stack_pop(s2); fprintf(stdout, "%d\n", i); } // but we can still play with the stack, can totally mess things up s2->stack_idx = 3; fprintf(stdout, "stack_idx is changed:\n"); while ( ! stack_empty(s2) ) { i = stack_pop(s2); fprintf(stdout, "%d\n", i); } return 0; }