TOPIC

Stacks

LIFO discipline: everything enters and leaves through the top.

WHY DID WE NEED STACKS?

THE WALLArrays and lists let you touch ANY element — but many problems (undo, nested brackets, function calls) only ever need the MOST RECENT thing, and full freedom just invites bugs.

THE IDEADeliberately RESTRICT access: push and pop at one end only — LIFO. Less power, more guarantees: the newest item is always the next one out, in O(1).

A stack of plates: you take the one you put down last. Ctrl+Z, the call stack, and bracket matching all work this way.

Choose a category