Adding More Elements: Stack Gets Taller
Now that we've pushed 10 into the stack, what happens when we push another element, say 20? Well, it will simply take its place on top of the last element we pushed, which is 10.
Visualizing a Stack with Multiple Elements
When we execute stack.push(20);, the stack's structure evolves as follows:
In this updated "box":10now has a companion,20, sitting right above it.20is the last-added element, making it the first one to be removed if we perform apopoperation.
Notice how 20 took its position on top of 10? This sequence of stacking elements on top of each other is a vivid illustration of the Last In, First Out (LIFO) principle in action.


