All pages 3 of 8
The stack
A pile of plates where you only ever touch the top one, so every move takes a single step.
Counted: 1 step
The steps
- Put 2 on top of the pile, on 7.
- 2 goes on top.
What it is
Think of a pile of clean plates by the sink. You put a new plate on the top. When you need a plate, you take the one on the top. You never pull one from the middle.
This is called a stack. Putting a thing on top is called a push. Taking the top thing off is called a pop. Looking at the top without taking it is called a peek.
How a move works
Push 1, then 7, then 4, and 4 is on top. A peek shows 4 in 1 step. A pop takes 4 off in 1 step, and 7 is on top again. Push 2, and the pile reads 1, 7, 2 from the bottom up.
Every move touches only the top plate. It does not matter if the pile holds three plates or three thousand. Each move is still 1 step.
Where you meet it
When you press undo, the app pops the last thing you did off a stack. A web browser keeps the pages you came from on a stack for its back button. A computer also keeps a stack of jobs. When it starts a small job in the middle of a big one, it pushes the big one, and pops it back when the small job is done.
Watch out for
A pile only has room for so many plates. This one holds 7. Push one more onto a full pile and it overflows, so the machine says no. A pop on an empty pile is a mistake too, because there is nothing to take.