Circular Queue allows efficient use of space by reusing empty spots left by removed elements. In a circular queue, you have two pointers: one for the front (where you remove items) and one for the rear (where you add items). When the rear reaches the end, it circles back to the start, making the queue a continuous loop. This approach helps in situations where you have a fixed amount of memory and need to handle a continuous flow of data.
function enqueue(value):
if front == rear and size == n:
alert "Queue is full."
else:
queue[rear] = value
rear = (rear + 1) % n
size = size + 1
function dequeue():
if front == rear and size == 0:
alert "Queue is empty."
else:
value = queue[front]
front = (front + 1) % n
size = size - 1
© 2025 SEE Algorithms. Code licensed under MIT, content under CC BY-NC 4.0.