Aug 30, 2024
front
is at position 0 and rear
at position (size - 1).(rear + 1) % n == front
front
and rear
start at -1 to indicate an empty queue.front
and rear
are both -1, set both to 0.(rear + 1) % n == front
rear
using (rear + 1) % n
.rear
.front
and rear
being -1 indicates an empty queue.front
equals rear
, reset both to -1 after dequeuing the element.front
.front
using (front + 1) % n
.i
equals rear
, and print elements.rear
to ensure all elements are displayed.front
of the queue without removing it.