Data Structures19 sections · 729 units
Open in Course

Stack Visualization

See it work

Trace some operations on an empty stack: Push 33: stack is [3][3]

Push 77: stack is [3,7][3, 7]

Push 11: stack is [3,7,1][3, 7, 1]

Pop: returns 11, stack is [3,7][3, 7]

Peek: returns 77, stack stays [3,7][3, 7]

Pop: returns 77, stack is [3][3]

The rightmost element is the "top." The last element you added is the first one you remove.