A circular queue, also called a ring buffer, stores a queue in a fixed array but treats the array as a ring: when rear moves past the last slot it wraps around to slot 0. This visualizer draws the buffer twice, as a ring of 8 slots and as the underlying array, with the front and rear pointers on both.
Enqueue, dequeue and peek are animated with the modulo arithmetic written out, for example rear = (7 + 1) mod 8 = 0. A size counter tells a full queue from an empty one. Every operation is O(1) and no slot is ever wasted.
How to use the Circular Queue Visualizer tool
- Type a value and press Enqueue; press Dequeue or Peek to read from the front.
- Watch the front and rear labels move around the ring and along the array.
- Keep going until rear wraps from index 7 back to index 0.
- Fill all 8 slots to see the full check, then empty it again.
Why use ToolOrca Circular Queue Visualizer
- Ring view and array view side by side
- Front and rear pointers with wrap-around
- Modulo arithmetic shown for every move
- Size counter to tell full from empty
- Pseudocode highlighted for every step
- Code in C++, Java, Python and JavaScript
How a circular queue works
The queue keeps three numbers: front (index of the first value), rear (index of the last value) and size. To enqueue, move rear one step with rear = (rear + 1) mod N and write the value there. To dequeue, read a[front] and move front = (front + 1) mod N. The mod N is what makes the indexes wrap around.
When front and rear point to the same slot, the queue could hold one value or be completely full after wrapping, so you need extra information. The two common solutions are a size counter (used here) or always leaving one slot empty, so the queue is full when (rear + 1) mod N = front.
Where ring buffers are used
Ring buffers are used wherever data streams in at a fixed rate and memory must not grow: audio and video buffers, network packet queues, keyboard buffers, logging the last N events, and producer-consumer queues between threads. Java’s ArrayDeque and Python’s collections.deque are built on related ideas.
Every visualizer on this site runs in your browser with the same controls: Play, Pause, Step forward, Step back and a speed slider. You can also drag the position slider to jump to any step, or focus the drawing and use the Space bar and arrow keys.
Frequently asked questions
What is a circular queue?
A queue stored in a fixed-size array whose ends are joined, so when the rear reaches the last slot it continues at slot 0. It reuses the space a simple array queue wastes.
How do you move the rear pointer in a circular queue?
rear = (rear + 1) mod capacity. With a capacity of 8, rear moves 5, 6, 7, 0, 1 and so on.
How do you know if a circular queue is full?
Keep a size counter and check size = capacity, or leave one slot unused and check (rear + 1) mod capacity = front.
What is the time complexity of a circular queue?
Enqueue, dequeue, peek and the full and empty checks are all O(1).