The Problem
In a standard Array-Queue, after enqueuing and dequeuing many times, the `front` and `rear` pointers hit the end of the array. Even if there are empty spots at the beginning, we can't use them!
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
A linear data structure that operates on FIFO but the last position is connected back to the first position to make a circle, overcoming the limitation of normal array-based queues.
In a standard Array-Queue, after enqueuing and dequeuing many times, the `front` and `rear` pointers hit the end of the array. Even if there are empty spots at the beginning, we can't use them!
A Circular Queue uses modulo arithmetic (or explicit checks) to wrap the `rear` pointer back to `0` if it hits the end and the front has advanced.
Empty: `front == -1`. Full: `(rear + 1) % size == front` (or `front == 0 && rear == size-1` along with `rear == front-1`).