Queue
You join at the back and leave from the front, like a queue at a counter.
Decision · step 5 of 10Queue: Enqueue, dequeue, peek
dequeue returns 5: the item that waited longest leaves first.
What you will see
FRONT -> items -> REAR; enqueue slides in at the rear, dequeue leaves from the front.
Cost
| enqueue | O(1) |
|---|---|
| dequeue | O(1) |
| peek | O(1) |
| search | O(n) |
| Space | O(n) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, try operations in any order.
Screen readers: Each element is an accessibility element with position, value and state; structural changes are announced per step.
Reduced motion: Elements appear at their destination with a crossfade; no travel longer than the element's own size.
Before this
Leads to
Topics that need this one first.
Taught by the same lesson
Queue covers these too, in the same run.