Tutorials

Queue


Queue Delete


We can delete element from the queue from the front only.

Queue delete opeartion by tutorialsinhand.com

 

From the above diagram we see:

  • If none of the element is deleted from the queue, initially Front (F) will be at 0.
  • When we delete the first element 7, F will be incremented by 1 (F = F +1). So F =1
  • When we delete the second element 11, F will again be incremented by 1. So F =2.
  • Front will keep on incrementing by 1 untill both front and rear become equal.
  • In third image, where 8 is the only element left we see both F and R equals 
  • When F==R, then after deleting the element from the queue we must set both F and R to -1. After last element element is deleted, F=R= -1 

Algorithm

Given algorithm delete element from front of the queue.

  1. Repeat step 2 to 7 if Front != -1
  2. Set item = queue[Front]
  3. If Front == Rear
  4. Set Front = -1 and Rear = -1
  5. Else Front = Front + 1
  6. End if
  7. Print deleted item
  8. Print "Queue is empty"


Please Share this page
Views : 35
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!