Friday, 13 April 2012

What is Queue ? Algorithms to insert and delete in queue.

What is Queue ?

Queue is ordered collection of homogeneous data elements in which insertion and deletion operation take place at two end . insertion allowed from starting of queue called FRONT point and deletion allowed from REAR end only
  • insertion operation is called ENQUEUE
  • deletion operation is called DEQUEUE 

Block Diagram of Queue

Conditions in Queue

  • FRONT < 0 ( Queue is Empty )
  • REAR = Size of Queue ( Queue is Full )
  • FRONT < REAR ( Queue contains at least one element )
  • No of elements in queue is : ( REAR - FRONT ) + 1

Restriction in Queue

we can not insert element directly at middle index (position) in Queue and vice verse for deletion. insertion operation possible at REAR end only and deletion operation at FRONT end, to insert we increment REAR and to delete we increment FRONT.

Algorithm for ENQUEUE (insert element in Queue)

Input : An element say ITEM that has to be inserted.
Output : ITEM is at the REAR of the Queue.
Data structure : Que is an array representation of queue structure with two pointer FRONT and REAR.

Steps:

1.  If ( REAR = size ) then //Queue is full
2.        print "Queue is full"
3.        Exit
4.  Else
5.        If ( FRONT = 0 ) and ( REAR = 0 ) then //Queue is empty
6.               FRONT = 1
7.        End if
8.        REAR = REAR + 1 // increment REAR
9.        Que[ REAR ] = ITEM
10. End if
11. Stop

Algorithm for DEQUEUE (delete element from Queue)

Input : A que with elements. FRONT and REAR are two pointer of queue .
Output : The deleted element is stored in ITEM.
Data structure : Que is an array representation of queue structure..

Steps:

1.  If ( FRONT = 0 ) then
2.        print "Queue is empty"
3.        Exit
4.  Else
5.        ITEM = Que [ FRONT ]
6.        If  ( FRONT  =  REAR )
7.               REAR = 0
8.               FRONT = 0
9.        Else
10.             FRONT  =  FRONT + 1
11.      End if
12. End if 
13. Stop 

What Next !!

Implement program using this Algorithms, if any query or suggestion then comment it.

Kindly Bookmark and Share it:

22 comments :

hitesh kumar on Thursday, January 07, 2016 5:53:00 am said...

Delete an Element from Array in C++

Thanks this is my home work

tofek khan on Tuesday, February 16, 2016 11:50:00 pm said...

nice, It is good tutorial for begineers.

tofek khan on Tuesday, February 16, 2016 11:52:00 pm said...

We need Implementation using java.

Unknown on Tuesday, June 14, 2016 7:31:00 pm said...

It's really helpful and and ending time reference.

Unknown on Tuesday, June 14, 2016 7:31:00 pm said...

It's really helpful and and ending time reference.

Unknown on Tuesday, June 14, 2016 7:31:00 pm said...

It's really helpful and and ending time reference.

Anonymous said...

Thanks ! Great work !

Unknown on Sunday, September 25, 2016 8:31:00 pm said...

"Queue is ordered collection of homogeneous data elements in which insertion and deletion operation take place at two end . insertion allowed from starting of queue called FRONT point and deletion allowed from REAR end only"

you've explained it wrong. Deletion in queue starts from front n insertion from rear......plz correct it

Unknown on Sunday, September 25, 2016 8:31:00 pm said...

"Queue is ordered collection of homogeneous data elements in which insertion and deletion operation take place at two end . insertion allowed from starting of queue called FRONT point and deletion allowed from REAR end only"

you've explained it wrong. Deletion in queue starts from front n insertion from rear......plz correct it

Venkat on Monday, November 07, 2016 11:23:00 am said...

Thank it is used for my exam

Sri on Monday, November 07, 2016 7:12:00 pm said...

Thanks for its good

Unknown on Tuesday, November 29, 2016 12:49:00 pm said...

to write an algorithm for of Queue, the above algorithm is ok for this question????

Anonymous said...

Awesome simple and easy !

Unknown on Thursday, May 25, 2017 3:53:00 pm said...

should be front-1 in deletion

Unknown on Wednesday, October 04, 2017 1:30:00 pm said...

Program is needed .please try to write program

Barsha on Friday, December 01, 2017 9:48:00 pm said...

there's this "if-else" statement existing already.... but what does if-then stand for? I didn't understand

Unknown on Monday, May 14, 2018 4:02:00 pm said...

It's damn good!

Unknown on Sunday, September 16, 2018 11:42:00 am said...

Nice

yaswanth on Wednesday, December 12, 2018 5:23:00 pm said...

delete an element after a given position in a double linked list

Ann on Tuesday, February 04, 2020 7:44:00 pm said...

It is very helpful for beginners

Unknown on Saturday, January 08, 2022 9:20:00 am said...

Helpful

Anonymous said...

Thanks 👍

Post a Comment

Any Query ? any suggestion ? comment here

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT