Displaying the Stack Contents
To view the entire stack content, the following function, info, can be used:
1 2 3 4 5 6 7 8 | fn info() { printf("stack: "); for (local i: int = 0; i < stackSize; ++i) { printf("[%d] ", stack[i]); } printf("\n"); } |
Modify the instructions in main so that after each push/pop operation, the top element and the entire stack content are displayed, producing output similar to the following:
1 2 3 4 5 6 7 | lehn$ ./a.out top = 3 stack: [3] top = 4 stack: [3] [4] top = 3 stack: [3] |