Skip to content
UPEEC

Stacks

Last-in, first-out (LIFO): push and pop at the same end.

Beginner
Comments 0

Operations push, pop and peek are all O(1)O(1).

stack = []
stack.append("(")     # push
stack.pop()           # pop

Uses: function call frames, undo history, expression evaluation, checking balanced brackets, and depth-first search. On a microcontroller, the hardware stack stores return addresses and local variables.

Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.

Discussion (0)

Sign in or join free to ask questions and discuss this topic.