Labs / Computer Science
Stack & Queue Playground
A stack and a queue receive the exact same stream of values, so you can watch two rules for ordering play out side by side. Push and pop the vertical stack, enqueue and dequeue the horizontal queue, or just leave auto-burst running — then click either structure to yank an element off it.
top —front —ops 0
What to try
- Push 1, 2, 3 and enqueue 1, 2, 3. Now remove one from each — which value leaves the stack, and which leaves the queue?
- The stack's top pointer and the queue's front pointer never point at the same element for long. When do they finally agree?
- Fill both to the brim. Why does the stack always hand back the newest value while the queue hands back the oldest?
- Turn on auto-burst and slow the speed down. Can you predict the next value to leave each structure before it slides out?
- If you only ever pushed and popped, could a stack ever behave like a queue — and what would that cost you?