Mental Model
A stack is like a pile where you add and remove items only from the top. Using an array, we keep track of the top position to add or remove elements.
Analogy: Imagine a stack of plates. You can only put a new plate on top or take the top plate off. The array holds the plates in order, and a pointer shows which plate is on top.
Array: [ _ , _ , _ , _ , _ ]
Top index: -1 (empty stack)
Visual:
Bottom -> [ ] [ ] [ ] [ ] [ ] β Top
βtop = -1 means no plates