Circular Queue (ADT) Simulator
Demonstrate wrap-around movement of front and rear pointers.
Algorithm
Current line is highlighted.
About This Simulation
This circular queue simulator shows a ring buffer with enqueue, dequeue and peek, the front and rear pointers wrapping around, and when overflow and underflow happen.
Features
- Enqueue, dequeue and peek on a circular array
- Front and rear pointers moving around the ring
- Overflow and underflow detection
- Pan, zoom and playback of every operation
Explanation
A circular queue is a queue stored in a fixed-size array where the last position is connected back to the first. When the rear reaches the end of the array it wraps around to index 0, so space freed by dequeues is reused.
How it works
- Keep front, rear and a count (or one empty slot) to tell full from empty.
- Enqueue: if the queue is full, report overflow. Otherwise set rear = (rear + 1) % capacity and store the value there.
- Dequeue: if the queue is empty, report underflow. Otherwise read the value at front and set front = (front + 1) % capacity.
- The queue is empty when count = 0 and full when count = capacity.
Why it matters
Circular buffers are used for keyboard and network buffers, audio and video streaming, producer-consumer problems and round robin scheduling. They give a queue with fixed memory and O(1) operations.
Frequently Asked Questions
How do you check if a circular queue is full?
If you keep a count, the queue is full when count = capacity. Without a count, a common method is to leave one slot empty: the queue is full when (rear + 1) % capacity = front.
Why is modulo used in a circular queue?
The modulo operator makes the index wrap around: (index + 1) % capacity goes back to 0 after the last position, which turns the array into a ring.
What is the advantage of a circular queue over a linear queue?
A linear array queue cannot reuse the slots before the front, so it can report full while space is free. A circular queue reuses those slots.
What is the time complexity of circular queue operations?
Enqueue, dequeue and peek all take O(1) time.
Topics covered
- Circular Queue
- Ring Buffer
- Modulo Arithmetic
- Front and Rear Pointers
- Queue Overflow and Underflow
Tags
- enqueue
- dequeue
- modulo
Related Simulations
Data Structures
B+ Tree
Insert, delete, search in a B+ tree visualiser
Data Structures
Stack (ADT) Simulator
Visualise push, pop, overflow, and underflow operations
Data Structures
Queue (ADT) Simulator
Show enqueue, dequeue, front, rear, overflow, and underflow.
Data Structures
Linked List Simulator
Insert, delete and search in a linked list stored in arrays, with the start and free pointers and every pointer change shown step by step.

