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 |
22 comments :
Delete an Element from Array in C++
Thanks this is my home work
nice, It is good tutorial for begineers.
We need Implementation using java.
It's really helpful and and ending time reference.
It's really helpful and and ending time reference.
It's really helpful and and ending time reference.
Thanks ! Great work !
"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
"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
Thank it is used for my exam
Thanks for its good
to write an algorithm for of Queue, the above algorithm is ok for this question????
Awesome simple and easy !
should be front-1 in deletion
Program is needed .please try to write program
there's this "if-else" statement existing already.... but what does if-then stand for? I didn't understand
It's damn good!
Nice
delete an element after a given position in a double linked list
It is very helpful for beginners
Helpful
Thanks 👍