â Lab
ð Stack â LIFO, one end, O(1)
Everything happens at the top: push, pop, peek â all O(1). Last in, first out. This is a call stack, an undo history, DFS.
size
2
top index
1
top value
8
empty?
no
stack â grows upward, top is the only door
5
8
what just happened (say it out loud)
Run an operation to see it step by step.
ėŽė: a stack restricts access to one end, which is exactly what makes push/pop O(1) and models nested/last-in-first-out work like function calls and backtracking.
âķ deep-dive videos â âstack data structure LIFO explainedâ