SlideShare une entreprise Scribd logo
1  sur  26
Queue
PREPARED BY:-
BHAVESH PARMAR(15ITS304)
 Queue
A queue is a linear Data structure in which insertion is performed at one end called rear and deletion is
performed at another end of the list is called front.
Type of Queue:
1.Simple Queue
2.Circularqueue
3.Dequeue
4.Priority Queue
 Representation of Queue
 The information in such a list is proceeds in the same order as it was received.
 Since insertion is performed at one end and deletion is performed at another end the element which is inserted
first is first to delete. So it is also known as First in First out (FIFO) or First Come First Serve (FCFS) data structure.
 Examples of Queue
A raw of students at registration counter.
Line of cars waiting to proceeds in some direction at traffic signal.
 Application of Queue
o A queue is the natural data structure for a system to serve its incoming requests. Most of
the process scheduling or disk scheduling algorithms in operating systems use queues.
o Computer hardware like a processor or a network card also maintain buffers in the form of
queues for incoming resource requests. A stack-like data structure causes starvation of the
first requests, and is not applicable in such cases.
o A mailbox or port to save messages to communicate between two users or processes in a
system is essentially a queue-like structure.
o Queue is widely used in Simulation.
 Operation on Simple Queue:
(1) Insert an element in to queue
(2) Delete an element from queue
1. Algorithm to insert an element in queue
PROCEDURE QINSERT (Q, F, R, N, Y)
• This function insert an element into the queue
• The Queue is represented by vector Q which contains N elements.
• F is a pointer which points to the front end
• R is a pointer which points to the rear end
• Y is the element to be inserted.
1) [Overflow?]
If R≥N then
Write (‘Overflow’)
2) [Increment rear pointer ]
RR+1
3) [Insert element]
Q[R]Y
4 ) [Is front pointer properly set?]
If F=0 then
F1
Return
2. Algorithm to delete an element from the queue
PROCEDURE QDELETE (Q, F, R)
• This function delete an element into the queue
• The Queue is represented by vector Q which contains N elements.
• F is a pointer which points to the front end
• R is a pointer which points to the rear end
• Y is the element to be inserted.
1) [Overflow?]
If R≥N then
Write (‘Overflow’)
2) [Delete element]
YQ [F]
3) [Queue empty?]
If F =R Then
F0
R0
Else FF+1
4) [Return element]
Return (y)
 For example consider following
operations:
o As shown in figure (a), we insert three elements 5, 10, 15 in simple queue.
o After that we delete 5 and 10 as shown in figure (b). Now even we have a free memory
space we cannot use that memory space. So simple queue results in wastage of memory
space.
o This problem can be solved by using circular queue.
 Circular Queue:
A circular queue is a queue in which elements are added and removed in a circular
fashion / manner, is called Circular Queue.
:
 Represent of circular Queue:
o As shown in figure (a), we insert eight elements 10, 20,30,40,50,60,70,80 in simple
queue. After that we delete 10, 20 and 30 as shown in figure (b). Now we have a free
memory space in circular queue and we can use that memory space by incrementing
rear pointer by 1(rear=0).
 Operations on Circular Queue
(1) Insert new element in to circular queue
(2) Delete element from circular queue
(1) Algorithm to insert element in circular queue
PROCEDURE CQINSERT (Q, F, R, N, Y)
o This function inserts an element in to circular queue.
o The Queue is represented by vector Q which contains N elements.
o F is a pointer which points to the front end
o R is a pointer which points to the rear end
o Y is the element to be inserted.
1) [Reset rear pointer?]
If R = N then
R 1
Else
RR + 1
2) [Overflow?]
if F= R then
Write (“queue overflow”)
Return
3) [Insert element]
Q[R]Y
4) [Is front pointer properly set?]
If F = 0 then
F1
Return
(2) Algorithm to delete element from circular queue.
PROCEDURE CQDELETE (Q, F, R,N)
o This function deletes an element from circular queue
o The Queue is represented by vector Q which contains N elements.
o F is a pointer which points to the front end
o R is a pointer which points to the rear end
o Y is temporary variable.
1) [Underflow]
If F = 0 then
Write (Underflow“)
2) [Delete element]
YQ[F]
3) [Queue empty?}
f F = R then
FßRß0
Return(Y)
4) [Increment front pointer}
If F = N then
F1
Else
FF+1
Return (Y)
 Dequeue:
Dequeue is a linier list in which insertion and deletion operation are performed at
either end of the queue.
Dequeue is also known double ended Queue…
Dequeue is shown below:
Operation on Dequeue
(1) Insert an element in to Dequeue
(2) Delete an element from Dequeue
 There are two types of Dequeue:
o Input restricted Dequeue: in input restricted Dequeue insertion operation is
performed at only one end of the queue.
o Output restricted Dequeue: in output restricted Dequeue deletion operation is
performed at only one end of the queue.
1.Insert operation in Dequeue
qinsert_beg(q,val)
1. If ( q  Rear = Max-1 AND q  FRONT=0]
Print “overflow Queue is full” and goto step 4
End If
2. q Front=-1
set q  Front=q  Rear=0
Set qDqueue [q  Front]= val
End If
3. If qRear != MAX=-1
Set num_item=qRear-qFRONT +1
Set i=qRear+1
set j=1
while j<=num_item
Set q  Dque[i]=q  Dque[i-1]
Set i=i-1
Set j=j+1
End While
Set qDque[i]=val
Set qFront=i
Set qRear =qRear +1
Else
Set qFront=qFront-1
Set qDque[qFront]=val
End if
4. End
2.Insert operation At the end of queue
Procedure qinsert_end(q,val)
1. If (qRear =Max-1 And qFront =0)
print “overflow” goto step4
End If
2. If qFront=-1
set q  Front=q  Rear=0
Set qDqueue [q  Front]= val and goto step4
End If
3. If q Rear = MAX-1
Set i=q  Front-1
While i< q  Rear
Set q Dque[i] =qDque[i+1]
Set i= i+1
End while
Set q  Dque[qRear]=val
Set q  Front=qFront-1
Else
Set q  Rear=qRear+1
Set q  Dque[qRear]=val
End IF
4. End
3.Delete operation in the beginning position
Procedure Qdelete_beg(q)
1. If q  Front = -1
Print “Underflow”
Return 0 and go to step 5
End If
2. Set del_val=q  Dque[qFront]
3.. If q  Front =q  Rear
Set q  front = q  Rear = -1
Else
Set qFront =q  front +1
End if
4. Return del_val
5. End
4.Delete operation At end of queue
Procedure delete_end(q)
1. If q  Front = -1
Print “Underflow”
Return 0 and go to step 5
End if
2. Set q del_val=q  Dque[qrear]
3. q  front = q  Rear
Set qfront = q Rear -1
Else
set q Rear = qrear-1
If qrear = -1
set qfront = -1
End if
End if
4. Return del_val
5.End
 Priority Queue:
A queue in which we are able to insert items or remove items from any position
based on some priority is known as priority queue.
R1 R2 …… Ri-1 O1 O2 ……. Oj-1 B1 B2 …… Bk-1
1 2 …… 1 2 2 …….. 2 3 3 …… 3
:
o Figure represents a priority queue of jobs waiting to use a computer
o Priorities of 1, 2, 3 have been attached to jobs of real time, on-line and batch
respectively.
o Figure shows how the single priority queue can be visualized as three separate
queues.
o When elements are inserted, they are always added at the end of one of the
queues as determined by the priorities
o Elements in the second queue are deleted only when the first queue is empty.
o Elements in the third queue are deleted only when the first and second queue are
empty.
 Operation on Priority Queue
1) Insert operation in priority Queue
2) Delete operation in priority Queue
1.Insert operation into priority Queue
Procedure Qinsert (q,val,prno) //prno is the priority of val
1). (qRear[prno]=MAX-1 AND qFront[prno]=0) OR
(qRear[prno]+1=qFront[prno]=0)
Print(“overflow queue”) and goto step-5
End If
2). If qRear[prno-1]=Max-1
set qRear[prno-1]= 0
Else
Set qRear[prno-1]=qRear[prno-1]+1
End if
3). Set qCqueue[prno-1] [qRear[prno-1]] =val.
4). If qFront[prno-1]= -1
Set qFront[prno-1] = 0
End if
5). End
2.delete operation on priority Queue
Procedure Qdelete(q)
1). Set flag=0,i=0
2). while I =MAX-1
If NOT(q  Front[prno])= -1
Set flag=1
Set del_val=q  Cqueue[1][q  Front[i]]
If qFront[ i ]=qRear[i]
Set q  Front[i] = qRear[i]=-1
Else If q  Rear[prno-1]=Max-1
Set q  Rear[prno-1]= 0
Else
Set q  Rear[prno-1]=q  Rear[prno-1]+1
End if
End if
Break //jump out from while loop
End if
Set i= i+1
End While
3). If FLAG=0
print(“underflow Queue”)
Return 0 and go to step 4
Else
Return Del_val
End IF
4). End
Queue

Contenu connexe

Tendances

My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
Tareq Hasan
 

Tendances (20)

Circular queue
Circular queueCircular queue
Circular queue
 
Team 6
Team 6Team 6
Team 6
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
 
QUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING CQUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING C
 
Queue
QueueQueue
Queue
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Stacks fundamentals
Stacks fundamentalsStacks fundamentals
Stacks fundamentals
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Queue
QueueQueue
Queue
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
Queue
QueueQueue
Queue
 

Similaire à Queue

Similaire à Queue (20)

Queue
QueueQueue
Queue
 
05 queues
05 queues05 queues
05 queues
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
 
QUEUES
QUEUESQUEUES
QUEUES
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
queue_final.pptx
queue_final.pptxqueue_final.pptx
queue_final.pptx
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 
sorting1.pptx
sorting1.pptxsorting1.pptx
sorting1.pptx
 
Queue
QueueQueue
Queue
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
 
Queue
QueueQueue
Queue
 

Plus de Bhavesh Parmar (10)

Inerrupt
InerruptInerrupt
Inerrupt
 
Mpeg7
Mpeg7Mpeg7
Mpeg7
 
Master page
Master pageMaster page
Master page
 
Training and placement reportmsword
Training and placement reportmswordTraining and placement reportmsword
Training and placement reportmsword
 
acknowledgement
acknowledgementacknowledgement
acknowledgement
 
index of project
index of projectindex of project
index of project
 
Training and placement
Training and placementTraining and placement
Training and placement
 
4 index
4 index4 index
4 index
 
3 page acknowledgement1
3 page acknowledgement13 page acknowledgement1
3 page acknowledgement1
 
Training and placement ppt
Training and placement pptTraining and placement ppt
Training and placement ppt
 

Dernier

Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
chumtiyababu
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 

Dernier (20)

Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 

Queue

  • 2.  Queue A queue is a linear Data structure in which insertion is performed at one end called rear and deletion is performed at another end of the list is called front. Type of Queue: 1.Simple Queue 2.Circularqueue 3.Dequeue 4.Priority Queue  Representation of Queue  The information in such a list is proceeds in the same order as it was received.  Since insertion is performed at one end and deletion is performed at another end the element which is inserted first is first to delete. So it is also known as First in First out (FIFO) or First Come First Serve (FCFS) data structure.
  • 3.  Examples of Queue A raw of students at registration counter. Line of cars waiting to proceeds in some direction at traffic signal.  Application of Queue o A queue is the natural data structure for a system to serve its incoming requests. Most of the process scheduling or disk scheduling algorithms in operating systems use queues. o Computer hardware like a processor or a network card also maintain buffers in the form of queues for incoming resource requests. A stack-like data structure causes starvation of the first requests, and is not applicable in such cases. o A mailbox or port to save messages to communicate between two users or processes in a system is essentially a queue-like structure. o Queue is widely used in Simulation.
  • 4.  Operation on Simple Queue: (1) Insert an element in to queue (2) Delete an element from queue 1. Algorithm to insert an element in queue PROCEDURE QINSERT (Q, F, R, N, Y) • This function insert an element into the queue • The Queue is represented by vector Q which contains N elements. • F is a pointer which points to the front end • R is a pointer which points to the rear end • Y is the element to be inserted. 1) [Overflow?] If R≥N then Write (‘Overflow’)
  • 5. 2) [Increment rear pointer ] RR+1 3) [Insert element] Q[R]Y 4 ) [Is front pointer properly set?] If F=0 then F1 Return
  • 6. 2. Algorithm to delete an element from the queue PROCEDURE QDELETE (Q, F, R) • This function delete an element into the queue • The Queue is represented by vector Q which contains N elements. • F is a pointer which points to the front end • R is a pointer which points to the rear end • Y is the element to be inserted. 1) [Overflow?] If R≥N then Write (‘Overflow’) 2) [Delete element] YQ [F] 3) [Queue empty?] If F =R Then F0 R0 Else FF+1 4) [Return element] Return (y)
  • 7.  For example consider following operations: o As shown in figure (a), we insert three elements 5, 10, 15 in simple queue. o After that we delete 5 and 10 as shown in figure (b). Now even we have a free memory space we cannot use that memory space. So simple queue results in wastage of memory space. o This problem can be solved by using circular queue.
  • 8.  Circular Queue: A circular queue is a queue in which elements are added and removed in a circular fashion / manner, is called Circular Queue. :  Represent of circular Queue:
  • 9. o As shown in figure (a), we insert eight elements 10, 20,30,40,50,60,70,80 in simple queue. After that we delete 10, 20 and 30 as shown in figure (b). Now we have a free memory space in circular queue and we can use that memory space by incrementing rear pointer by 1(rear=0).  Operations on Circular Queue (1) Insert new element in to circular queue (2) Delete element from circular queue
  • 10. (1) Algorithm to insert element in circular queue PROCEDURE CQINSERT (Q, F, R, N, Y) o This function inserts an element in to circular queue. o The Queue is represented by vector Q which contains N elements. o F is a pointer which points to the front end o R is a pointer which points to the rear end o Y is the element to be inserted. 1) [Reset rear pointer?] If R = N then R 1 Else RR + 1 2) [Overflow?] if F= R then Write (“queue overflow”) Return 3) [Insert element] Q[R]Y
  • 11. 4) [Is front pointer properly set?] If F = 0 then F1 Return
  • 12. (2) Algorithm to delete element from circular queue. PROCEDURE CQDELETE (Q, F, R,N) o This function deletes an element from circular queue o The Queue is represented by vector Q which contains N elements. o F is a pointer which points to the front end o R is a pointer which points to the rear end o Y is temporary variable. 1) [Underflow] If F = 0 then Write (Underflow“) 2) [Delete element] YQ[F] 3) [Queue empty?} f F = R then FßRß0 Return(Y)
  • 13. 4) [Increment front pointer} If F = N then F1 Else FF+1 Return (Y)
  • 14.  Dequeue: Dequeue is a linier list in which insertion and deletion operation are performed at either end of the queue. Dequeue is also known double ended Queue… Dequeue is shown below:
  • 15. Operation on Dequeue (1) Insert an element in to Dequeue (2) Delete an element from Dequeue  There are two types of Dequeue: o Input restricted Dequeue: in input restricted Dequeue insertion operation is performed at only one end of the queue. o Output restricted Dequeue: in output restricted Dequeue deletion operation is performed at only one end of the queue.
  • 16. 1.Insert operation in Dequeue qinsert_beg(q,val) 1. If ( q  Rear = Max-1 AND q  FRONT=0] Print “overflow Queue is full” and goto step 4 End If 2. q Front=-1 set q  Front=q  Rear=0 Set qDqueue [q  Front]= val End If 3. If qRear != MAX=-1 Set num_item=qRear-qFRONT +1 Set i=qRear+1 set j=1 while j<=num_item Set q  Dque[i]=q  Dque[i-1] Set i=i-1
  • 17. Set j=j+1 End While Set qDque[i]=val Set qFront=i Set qRear =qRear +1 Else Set qFront=qFront-1 Set qDque[qFront]=val End if 4. End 2.Insert operation At the end of queue Procedure qinsert_end(q,val) 1. If (qRear =Max-1 And qFront =0) print “overflow” goto step4 End If
  • 18. 2. If qFront=-1 set q  Front=q  Rear=0 Set qDqueue [q  Front]= val and goto step4 End If 3. If q Rear = MAX-1 Set i=q  Front-1 While i< q  Rear Set q Dque[i] =qDque[i+1] Set i= i+1 End while Set q  Dque[qRear]=val Set q  Front=qFront-1 Else Set q  Rear=qRear+1 Set q  Dque[qRear]=val End IF 4. End
  • 19. 3.Delete operation in the beginning position Procedure Qdelete_beg(q) 1. If q  Front = -1 Print “Underflow” Return 0 and go to step 5 End If 2. Set del_val=q  Dque[qFront] 3.. If q  Front =q  Rear Set q  front = q  Rear = -1 Else Set qFront =q  front +1 End if 4. Return del_val 5. End
  • 20. 4.Delete operation At end of queue Procedure delete_end(q) 1. If q  Front = -1 Print “Underflow” Return 0 and go to step 5 End if 2. Set q del_val=q  Dque[qrear] 3. q  front = q  Rear Set qfront = q Rear -1 Else set q Rear = qrear-1 If qrear = -1 set qfront = -1 End if End if 4. Return del_val 5.End
  • 21.  Priority Queue: A queue in which we are able to insert items or remove items from any position based on some priority is known as priority queue. R1 R2 …… Ri-1 O1 O2 ……. Oj-1 B1 B2 …… Bk-1 1 2 …… 1 2 2 …….. 2 3 3 …… 3 : o Figure represents a priority queue of jobs waiting to use a computer o Priorities of 1, 2, 3 have been attached to jobs of real time, on-line and batch respectively. o Figure shows how the single priority queue can be visualized as three separate queues.
  • 22. o When elements are inserted, they are always added at the end of one of the queues as determined by the priorities o Elements in the second queue are deleted only when the first queue is empty. o Elements in the third queue are deleted only when the first and second queue are empty.  Operation on Priority Queue 1) Insert operation in priority Queue 2) Delete operation in priority Queue
  • 23. 1.Insert operation into priority Queue Procedure Qinsert (q,val,prno) //prno is the priority of val 1). (qRear[prno]=MAX-1 AND qFront[prno]=0) OR (qRear[prno]+1=qFront[prno]=0) Print(“overflow queue”) and goto step-5 End If 2). If qRear[prno-1]=Max-1 set qRear[prno-1]= 0 Else Set qRear[prno-1]=qRear[prno-1]+1 End if 3). Set qCqueue[prno-1] [qRear[prno-1]] =val. 4). If qFront[prno-1]= -1 Set qFront[prno-1] = 0 End if 5). End
  • 24. 2.delete operation on priority Queue Procedure Qdelete(q) 1). Set flag=0,i=0 2). while I =MAX-1 If NOT(q  Front[prno])= -1 Set flag=1 Set del_val=q  Cqueue[1][q  Front[i]] If qFront[ i ]=qRear[i] Set q  Front[i] = qRear[i]=-1 Else If q  Rear[prno-1]=Max-1 Set q  Rear[prno-1]= 0 Else Set q  Rear[prno-1]=q  Rear[prno-1]+1 End if End if Break //jump out from while loop End if Set i= i+1 End While
  • 25. 3). If FLAG=0 print(“underflow Queue”) Return 0 and go to step 4 Else Return Del_val End IF 4). End

Notes de l'éditeur

  1. qRear[]