Circular Queue
A Circular Queue is a data structure that uses a fixed-size array to store elements in a circular manner. Unlike a regular queue, where the first element is removed from the front and new elements are added at the back, a circular queue allows the rear to wrap around to the front when it reaches the end of the array. This efficient use of space helps prevent wasted slots in the array.
In a circular queue, two pointers, often called front and rear, are used to track the positions of the first and last elements. When the queue is empty, both pointers point to the same position. When an element is added or removed, the pointers are updated accordingly, allowing for continuous use of the array without needing to shift elements.