ChoralSoft Learn

Stacks and queues, side by side

Last in, first out versus first in, first out, and why the difference matters.

Add and remove, two different ways

A stack gives back the newest item first (like plates). A queue gives back the oldest first (like a line at a shop). Add the same items to both, then remove one and compare.

Stack (last in, first out)

empty

Next out: –

Queue (first in, first out)

empty

Next out: –

Add a few items, then remove one.

Stacks power undo, back buttons and depth-first search. Queues power print jobs and breadth-first search. See both in the maze.