StackEasy

Stack Foundation Visualizer

What is Stack Foundation

A stack is a list where the last value pushed is the first value popped. The open end is the top.

Approach

The picture pushes three values, then pops one. The top is drawn on the left of the stack row.

Visualization & algorithm

Push, then pop
stack = []
push each value
top is the last pushed value
pop removes the top
peek reads the top
Step 0/0 Answer —

The finished picture is on screen when the page opens. Next and Play start from the first step. The controls sit under the picture and the pseudocode.

Complexity

PieceCostWhy
Push or popO(1)Only the top changes.
SpaceO(n)Every pushed value is stored until it is popped.

Implementation

stack = []
stack.append(1)   # push
stack.append(2)
top = stack[-1]   # peek
stack.pop()       # pop