Queue Operations :Insertion,Deletion and Traversal



ALGORITHM : ENQUE(VALUE,QUEUE,FRONT,REAR)
Here REAR is position for input of data into queue,FRONT is position for deletion of data and VALUE is the item to be inserted.This algorithm will insert data into QUEUE. 

1.If REAR=N-1 then : print overflow and return.
2. Set REAR=REAR+1.
3.Set QUEUE[REAR]=VALUE.
4.If FRONT=-1 then :Set FRONT=FRONT+1.
5.Exit


ALGORITHM : DEQUE(QUEUE,FRONT,REAR)
Here REAR is position for input of data into queue,FRONT is position for deletion of data .This algorithm will delete a data from QUEUE. 

1.If FRONT=-1 then : print underflow and return.
2.print QUEUE[FRONT].
3.If FRONT=REAR then :Set FRONT=REAR=-1.
    Else :Set FRONT=FRONT+1.
4.Exit.

ALGORITHM : TRAVERSAL(QUEUE,FRONT,REAR)
Here REAR is position for input of data into queue,FRONT is position for deletion of data .This algorithm will display all the data from QUEUE.

1.If FRONT=-1 then : print queue is empty and return.
2.Set I=FRONT.
3.If I<=REAR then :print QUEUE[I].
4.Set I=I+1.
5.Goto 3.
[End Of Loop.]
6.Exit.

If you have any suggestions regarding this post, please comment below in the comment section.

No comments

Leave a Reply

Followers