- Linear queue follows First In First Out rule.
- We insert elements from Rear and delete from Front.
- In linear queue “Front” is fixed location.
- When we delete an element from the queue, shifting of elements takes much time.
- In circular queue, we are representing the Queue in circle form.
- We can move front location also after deletion of element from the queue.
- As front value is not fixed, front and rear values starts with -1
- We declare array variable with fixed size.
- Front and Rear variables are used to process the location data.
- Front and Rear variables not pointing to any location initially.
location is not fixed in Circular Queue.
- int cqueue;
- int front=-1;
Operations: We can perform following operations on Circular Queue.
- The following diagrams describe the queue initially.
- Inserting elements from ‘rear’.
- First insertion changes both the values of front and rear variables.
- Continues insertion of elements results “Queue is full”.
- Deleting elements using ‘front’ variable.
- After deletion of element, front value increase by 1.
When we try to insert the element and the rear value reaches size-1, again rear value starts from 0.
- Keep on inserting elements reaches “Queue is full” condition.
- Two conditions gives “Queue is full” situation.
While deleting, if it reaches the location “size-1”, it starts with 0 again in the next cycle.
- When front and rear values are equal means Queue has only 1 element.
- When we remove the last element from the queue, then front and read values become -1.