Operations on Circular Queue:
- qInsert(value) This function is used to insert an element into the circular queue. In a circular queue, the new element is always inserted at Rear position.Steps:
- Create a new node dynamically and insert value into it.
- Check if front==NULL, if it is true then front = rear = (newly created node)
- If it is false then rear=(newly created node) and rear node always contains the address of the front node.
- qRemove() This function is used to delete an element from the circular queue. In a queue, the element is always deleted from front position.Steps:
- Check whether queue is empty or not means front == NULL.
- If it is empty then display Queue is empty. If queue is not empty then step 3
- Check if (front==rear) if it is true then set front = rear = NULL else move the front forward in queue, update address of front in rear node and return the element.
Here is an example of inserting and removing a few values with a circular queue
This is the same as the non-circular EXCEPT that you must update the rear->next value to point to the head when you qRemove(), and set the new rear->next when you qInsert().
"Circular Queue | Set 2 (Circular Linked List Implementation)" by Arnab Kundu is licensed under CC BY-SA 4.0