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:

7 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 !

Post a Comment

Any Query ? any suggestion ? comment here

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT