Circular Queue
Idea Like You Are 10
Imagine seats arranged in a circle.
After the last seat, you come back to the first seat.
That is how a circular queue works.
It reuses free spaces.
Why It Is Better Than Simple Queue
In a simple queue, removed spaces in front may get wasted.
In a circular queue, rear can wrap around and use them again.
Representation
Full And Empty Conditions
Queue is empty when:
Queue is full when:
Algorithms
Enqueue
Time: O(1)
Dequeue
Time: O(1)
Display
Time: O(n)
Complexity Summary
| Operation | Time |
|---|---|
| Enqueue | O(1) |
| Dequeue | O(1) |
| Front | O(1) |
| Rear | O(1) |
| Display | O(n) |
Main Advantage
Better memory usage than a simple array queue.