LESSON 3.02 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW
Stacks and queues
Watch a stack and two queues take the same items and give them back.
Needs3.01 Linked lists
Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.
Go Pro · $8.25/moEXPLAINER · 3.02 · QUEUE BAYMOVES · STACK 0 · LIST QUEUE 0 · RING 0
01
Stage 1 of 5 · Push items
Three containers take A to E, one push at a time. The ring buffer writes each item at slot (h + k) mod C.
Explain it simply
You see three containers that get the same letters, A to E. The top two are Python lists, and each new letter goes on the end. The bottom one is a ring buffer, a fixed row of 6 slots. It writes each letter in the next free slot after its head, the slot it reads next.
The stack holds A, B, C, D, E, with E on top. The list queue holds A, B, C, D, E. The ring has 6 slots, head 0 and 5 items: A, B, C, D, E.
itemslot, head, sizemoved or dropped itempopped itemempty slot
Toy: 3 containers · 5 to 9 items · a ring of 4 to 8 slots · one fixed program of pushes and pops
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
The ring writes a new item k slots after its head, wrapping at C.
PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
- 4 more stages and 3 live controls
- 2 mix-up cards and 3 predict-then-reveal checks
- Watch it as a narrated video, in three voices
- Every Pro lesson and capstone · 656 in total
$99 a year, or $15 a month. Cancel any time.