/* * ISA 563, Spring 2011 * Copyleft by Muhammad Abdulla */ #include #include #include "stack4.h" #define MAXLINE 32 int main ( int argc, char *argv[] ) { int i; char line[MAXLINE]; fprintf(stdout, "Please enter numbers to stacked:\n"); Stack s1 = stack_new(); Stack s2 = stack_new(); while ( fgets(line, sizeof(line), stdin) ) { i = atoi(line); if ( ! stack_full(s1) ) { stack_push(s1, i); } } 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); } } fprintf(stdout, "Numbers in original order:\n"); while ( ! stack_empty(s2) ) { i = stack_pop(s2); fprintf(stdout, "%d\n", i); } // can we mess things up this time? (should give a compiler error) // s2->stack_idx = 3; // clean up stack_free(s1); stack_free(s2); return 0; }