All algorithms
Stack (LIFO)
A stack is a Last-In-First-Out container. push adds to the top, pop removes from the top, peek reads the top without removing. All three operations are O(1).
time push/pop/peek O(1)
space O(n)
Press Tab out of the box or click Resetto regenerate frames from the current input.
Visualization
No frames yet — edit input and click Run.
—
Pseudocode
push(x): elements.append(x); top = len-1 pop(): x = elements[top]; elements.pop(); top -= 1; return x peek(): return elements[top]