How A Stack Works
How A Stack Works
1. A pointer called TOP is used to keep track of the top element in the
stack.
2. When initializing the stack, we set its value to -1 so that we can check if
the stack is empty by comparing TOP == -1.
3. On pushing an element, we increase the value of TOP and place the new
element in the position pointed to by TOP.
4. On popping an element, we return the element pointed to by TOP and
reduce its value.
5. Before pushing, we check if the stack is already full
6. Before popping, we check if the stack is already empty
Stack Operations