Draw the under lying data structure and elements of an array
Draw the under lying data structure and elements of an array being used to implement a stack as the following push and pop statements are executed: push(11), push(2), push(55), push(4), pop(), pop(), push(70), push(20), push(3), pop(). Re-draw the array AFTER EACH OPERATION and indicate the # of EACH INDEX!
Solution
Assume initially the Stack array is of size 5. And top is pointing -1.
PUSH(11): top will now be incremented, and is pointing to 0.
PUSH(2): top will now be incremented, and is pointing to 1.
PUSH(55): top will now be incremented, and is pointing to 2.
PUSH(4): top will now be incremented, and is pointing to 3.
POP(): top will now be decremented, and is pointing to 2.
POP(): top will now be decremented, and is pointing to 1.
PUSH(70): top will now be incremented, and is pointing to 2.
PUSH(20): top will now be incremented, and is pointing to 3.
PUSH(3): top will now be incremented, and is pointing to 4.
POP(): top will now be decremented, and is pointing to 3.
Therefore, at the end of all the operations, this will be status of the stack array.
| Index | 0 | 1 | 2 | 3 | 4 |
| Value |
