Scenarios where elements can be inserted into a circular queue are −
- If
(rear + 1)%maxsize = front
, then the queue is full. In this case, an overflow occurs, so the insertion cannot be performed in the queue. - If
rear != max - 1
, thenrear
will be incremented tomod(maxsize)
and the new value will be inserted into the backend of the queue. - If
front != 0
andrear = max - 1
, the queue is not full, so setrear
the value of to0
and insert the new element there.