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