{ } LinearCore interactive
Stack
Last-In-First-Out. Push, pop, peek.
stack
size 3
12
5
27← top
LIFO — the last value pushed is the first popped.
top of stack ↑
How it works
A stack is a LIFO collection: the last thing you push is the first thing you pop. It mirrors the call stack your program already runs on, and it's the secret engine behind undo, expression parsing, and backtracking.
Mental models
- Only the top is reachable — that constraint is the feature.
- Recursion is a stack: each call frame pushes, each return pops.
Complexity
- Push
- O(1)
- Pop
- O(1)
- Peek
- O(1)
- Search
- O(n)
- Space
- O(n)
Reach for it when
- Undo/redo, browser back button.
- Balanced-parentheses & expression evaluation.
- DFS and backtracking without recursion.