Concept:
A circular queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle.
• Modulo Arithmetic: Used to wrap indices back to 0 when they reach the end of the array.
• Space Management: A circular queue solves the "waste of space" problem in a standard linear array-based queue.
Step 1: Understanding the indices.
In a circular queue:
• Front: Points to the element to be removed.
• Rear: Points to the last element inserted.
Step 2: Defining the "Next" position.
The next position after rear is calculated as $(rear + 1) \% MAX$. This ensures that if $rear$ is at the last index ($MAX-1$), the next index becomes 0.
Step 3: Determining the Full condition.
The queue is considered full when the "next" position of $rear$ would collide with $front$. In many implementations, one slot is intentionally left empty to distinguish between a "Full" and "Empty" queue. Thus, the standard condition is $(rear + 1) \% MAX == front$.