Stacks & Queues

LIFO and FIFO

A stack is last-in-first-out (LIFO): the last thing you pushed is the first thing you pop. Think of an undo history β€” the most recent action undoes first.

A queue is first-in-first-out (FIFO): the first thing in is the first thing out. Think of a job queue β€” the oldest job runs next.

Both are just disciplined ways of adding and removing from a list. What matters is the cost of those operations.