← Lab

🎟ïļ Queue — a ring buffer (FIFO, O(1))

FIFO without shifting: a fixed array with head + tail pointers that wrap around. enqueue at tail, dequeue at head, both O(1).

capacity
6
size
3
head
0
tail
3
ring buffer — head dequeues, tail enqueues, both wrap
10
0
head
20
1
30
2
3
tail
4
5
what just happened (say it out loud)

Run an operation to see it step by step.

ė‚Žėƒ: a ring buffer reuses the same array by moving pointers modulo capacity, so a queue never shifts elements — that's how enqueue/dequeue stay O(1) with fixed memory.
â–ķ deep-dive videos — “circular buffer ring buffer queue explained”