cconnected.
Understand the pattern. Find your own way.Find your starting point
Your learning feed/Idea 5 of 218
Ideas this builds on
Start small05 / 218

Take the top plate first

Picture

Put a blue plate down. Put a pink plate on top. The pink one is the easiest to take next. A stack follows this last-in, first-out order.

Predict

Blue goes in first, then pink. Which plate comes out first?

Let's look

Pink, the last one added.

A little Python, if you want it
plates = []
plates.append("blue")
plates.append("pink")
assert plates.pop() == "pink"
assert plates == ["blue"]

append adds to the end. pop() takes from that same end. Paused function calls also form a stack: finish the newest unfinished call, then return to its caller.

Change one rule

We want the oldest item first. Would this stack rule do that?

Let's try it

No. We need the queue rule next.

Connect

Compare a queue. Keep the stack picture for recursion and depth-first search.