SlideShare a Scribd company logo
QUEUES
TOPICS COVERED
•Definition of Queue
•Representation of Queue
•Operations of Queue
•Types of Queue
•Applications of Queue
INTRODUCTION
DEFINITION
• A queue is a FIFO (first-in, first-out) data structure in which the element that is
inserted first is the first one to be taken out.
• A queue is open at both its ends.
• The elements in a queue are added at one end called the rear and removed
from the other end called the front.
• Queues can be implemented by using either arrays or linked lists
• One end is always used to insert data (enqueue) and the other is used to
remove data (dequeue).
REPRESENTATION OF QUEUE
OUT 2 3 IN
FRONT
REAR
1
ENQUEUE
DEQUEUE
1 2 3 4
OPERATIONS OF QUEUE
• Queue operations may involve initializing or defining the queue, utilizing it, and
then completely erasing it from the memory. the basic operations associated with
queues are,
• enqueue() − add (store) an item to the queue.
• dequeue() − remove (access) an item from the queue.
• peek() − Gets the element at the front of the queue without removing it.
• isfull() − Checks if the queue is full.
• isempty() − Checks if the queue is empty.
• In queue, we always dequeue (or access) data, pointed by front pointer and while
enqueuing (or storing) data in the queue we take help of rear pointer.
ENQUEUE
Void Enqueue (int X)
{
if (Rear > = MaxSize)
print(“Queue Overflow”);
else
{
rear = Rear + 1;
Queue[Rear] = X;
}
}
1 2 3 4
FRONT REAR
1 2 3 4 X
REARFRONT
DEQUEUE
Void Dequeue ( )
{
if (Front < 0 ) && ( Rear == -1)
print ( “ Queue Underflow”);
else
{
X = Queue[Front];
if( Front == Rear )
{
Front = 0;
Rear = -1;
}
else
Front = Front + 1;
}
}
50
50 60 60
EMPTY QUEUE
0 1 2 3 4
R F Rear = -1 Front = 0
ENQUEUE (50 )
0 1 2 3 4
R, F
0 1 2 3 4
Front Rear ENQUEUE ( 60)
0 1 2 3 4
R, F DEQUEUE( 50 )
0 1 2 3 4
R F Rear = -1 Front = 0
DEQUEUE( 60 )
TYPES OF QUEUES
• Double Ended Queue ( Dequeue)
• Circular Queue
• Priority Queue
• Multiple Queue
DOUBLE ENDED QUEUE
• Insertion and deletion operations are allowed at both the ends.
• Types are,
• Input restricteddequeue
• Output restricteddequeue
Front End Rear End
10 20 30 40 50 60
• Input restricted dequeue
• Insertion allowed at one end and
deletion allowed at both the ends.
• Output restricted dequeue
• Deletion allowed at one end and
insertion allowed at both the ends.
CIRCULAR QUEUE
• The insertion of a new element is performed at the very first location of
the queue if the last location of the queue is full, in which the first
element comes just after the last element.
• Advantage:
• it overcomes the problem of unutilized space in linear queues, when it
is implemented as array.
Q[1]
Q[2]
Q[3]
Q[4]
Q[5]
Q[6]
Q[7] Q[0]
Front
10
20
30
40
10
20
30
4050
60
70
80
Rear
Front
Rear
OPERATIONS OF CIRCULAR QUEUE
• To perform the insertion operation in
the circular queue , the position of the
element is calculated by the relation as,
Rear = ( Rear + 1) % MaxSize
Queue [ Rear ] = Value
To perform the deletion operation ,
the position of the Front pointer is
calculated by the relation,
Value = Cqueue[Front];
Front = (Front +1) % MaxSize;
INSERTION
void Cenqueue ( int X )
{
if ( Front == (Rear + 1) % MaxSize
print ( “ Queue is Overflow “ );
else
{
if ( Front == -1)
Front = Rear = 0;
else
Rear = ( Rear + 1) % MaxSize;
Cqueue [ Rear ] = X;
}
}
DELETION
Int Dequeue ( )
{
if ( front = = - 1)
print ( “ Queue is underflow “ );
else
{
X = Cqueue [Front];
if ( Front = = Rear )
Front = Rear = – 1;
else
Front = (Front + 1) % MaxSize;
}
return (X);
}
PRIORITY QUEUE
• Insertion and deletion can be performed in any position of the queue based
on some priority.
• An element with higher priority is processed before an element with a
lower priority.
• Two elements with the same priority are processed on a first-come-first-
served (FCFS) basis.
• Used to sort the elements using heap sort.
APPLICATIONS OF QUEUE
• Batch Processing in operating systems
• Simulation
• Queueing theory
• Computer Networks

More Related Content

What's hot

Sorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - NotesSorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - Notes
Omprakash Chauhan
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
CIIT Atd.
 
Queue-Data Structure
Queue-Data StructureQueue-Data Structure
Queue-Data Structure
Paurav Shah
 
Queue
QueueQueue
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
Omprakash Chauhan
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
sandeep54552
 
Nested loops
Nested loopsNested loops
Nested loops
obrienduke
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListPTCL
 
Queue
QueueQueue
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
Bhavesh Sanghvi
 
Queues-handouts
Queues-handoutsQueues-handouts
Queues-handouts
Fajar Baskoro
 
Queue
QueueQueue
Stack and queue
Stack and queueStack and queue
Stack and queue
Shakila Mahjabin
 
Stack Data Structure V1.0
Stack Data Structure V1.0Stack Data Structure V1.0
Stack Data Structure V1.0
Zidny Nafan
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arraystameemyousaf
 
Stack
StackStack
computer notes - Data Structures - 38
computer notes - Data Structures - 38computer notes - Data Structures - 38
computer notes - Data Structures - 38ecomputernotes
 

What's hot (20)

Sorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - NotesSorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - Notes
 
Queue
QueueQueue
Queue
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
Queue-Data Structure
Queue-Data StructureQueue-Data Structure
Queue-Data Structure
 
Queue
QueueQueue
Queue
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
 
Nested loops
Nested loopsNested loops
Nested loops
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
Queue
QueueQueue
Queue
 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
 
Queues-handouts
Queues-handoutsQueues-handouts
Queues-handouts
 
Queue
QueueQueue
Queue
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Stack Data Structure V1.0
Stack Data Structure V1.0Stack Data Structure V1.0
Stack Data Structure V1.0
 
03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays03 stacks and_queues_using_arrays
03 stacks and_queues_using_arrays
 
Stack
StackStack
Stack
 
computer notes - Data Structures - 38
computer notes - Data Structures - 38computer notes - Data Structures - 38
computer notes - Data Structures - 38
 

Similar to QUEUES

Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
Dabbal Singh Mahara
 
Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
btechsmartclass
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
Soumen Santra
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
MuhammadUmerIhtisham
 
6 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart36 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart3
SSE_AndyLi
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
Tribhuvan University
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
SherinRappai
 
Queue
QueueQueue
Queue
QueueQueue
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
Mandeep Singh
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
singhprpg
 
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
RAtna29
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
Ssankett Negi
 
stack & queue
stack & queuestack & queue
stack & queue
manju rani
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
MattFlordeliza1
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
shaik faroq
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
NuraMohamed9
 

Similar to QUEUES (20)

Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
6 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart36 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart3
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Queue
QueueQueue
Queue
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
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
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
stack & queue
stack & queuestack & queue
stack & queue
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 

Recently uploaded

CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
Kamal Acharya
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
884710SadaqatAli
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
wendy cai
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
Amil baba
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
Emre Günaydın
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Top 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering ScientistTop 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering Scientist
gettygaming1
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturing
ssuser0811ec
 
fluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerfluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answer
apareshmondalnita
 
Antenna efficency lecture course chapter 3.pdf
Antenna  efficency lecture course chapter 3.pdfAntenna  efficency lecture course chapter 3.pdf
Antenna efficency lecture course chapter 3.pdf
AbrahamGadissa
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
NurvisNavarroSanchez
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
AbrahamGadissa
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
VigneshvaranMech
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
Kamal Acharya
 

Recently uploaded (20)

CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Top 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering ScientistTop 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering Scientist
 
Introduction to Casting Processes in Manufacturing
Introduction to Casting Processes in ManufacturingIntroduction to Casting Processes in Manufacturing
Introduction to Casting Processes in Manufacturing
 
fluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answerfluid mechanics gate notes . gate all pyqs answer
fluid mechanics gate notes . gate all pyqs answer
 
Antenna efficency lecture course chapter 3.pdf
Antenna  efficency lecture course chapter 3.pdfAntenna  efficency lecture course chapter 3.pdf
Antenna efficency lecture course chapter 3.pdf
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
 
Digital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdfDigital Signal Processing Lecture notes n.pdf
Digital Signal Processing Lecture notes n.pdf
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
 

QUEUES

  • 2. TOPICS COVERED •Definition of Queue •Representation of Queue •Operations of Queue •Types of Queue •Applications of Queue
  • 4. DEFINITION • A queue is a FIFO (first-in, first-out) data structure in which the element that is inserted first is the first one to be taken out. • A queue is open at both its ends. • The elements in a queue are added at one end called the rear and removed from the other end called the front. • Queues can be implemented by using either arrays or linked lists • One end is always used to insert data (enqueue) and the other is used to remove data (dequeue).
  • 5. REPRESENTATION OF QUEUE OUT 2 3 IN FRONT REAR 1 ENQUEUE DEQUEUE 1 2 3 4
  • 6. OPERATIONS OF QUEUE • Queue operations may involve initializing or defining the queue, utilizing it, and then completely erasing it from the memory. the basic operations associated with queues are, • enqueue() − add (store) an item to the queue. • dequeue() − remove (access) an item from the queue. • peek() − Gets the element at the front of the queue without removing it. • isfull() − Checks if the queue is full. • isempty() − Checks if the queue is empty. • In queue, we always dequeue (or access) data, pointed by front pointer and while enqueuing (or storing) data in the queue we take help of rear pointer.
  • 7. ENQUEUE Void Enqueue (int X) { if (Rear > = MaxSize) print(“Queue Overflow”); else { rear = Rear + 1; Queue[Rear] = X; } } 1 2 3 4 FRONT REAR 1 2 3 4 X REARFRONT
  • 8. DEQUEUE Void Dequeue ( ) { if (Front < 0 ) && ( Rear == -1) print ( “ Queue Underflow”); else { X = Queue[Front]; if( Front == Rear ) { Front = 0; Rear = -1; } else Front = Front + 1; } }
  • 9. 50 50 60 60 EMPTY QUEUE 0 1 2 3 4 R F Rear = -1 Front = 0 ENQUEUE (50 ) 0 1 2 3 4 R, F 0 1 2 3 4 Front Rear ENQUEUE ( 60) 0 1 2 3 4 R, F DEQUEUE( 50 ) 0 1 2 3 4 R F Rear = -1 Front = 0 DEQUEUE( 60 )
  • 10. TYPES OF QUEUES • Double Ended Queue ( Dequeue) • Circular Queue • Priority Queue • Multiple Queue
  • 11. DOUBLE ENDED QUEUE • Insertion and deletion operations are allowed at both the ends. • Types are, • Input restricteddequeue • Output restricteddequeue Front End Rear End 10 20 30 40 50 60
  • 12. • Input restricted dequeue • Insertion allowed at one end and deletion allowed at both the ends. • Output restricted dequeue • Deletion allowed at one end and insertion allowed at both the ends.
  • 13. CIRCULAR QUEUE • The insertion of a new element is performed at the very first location of the queue if the last location of the queue is full, in which the first element comes just after the last element. • Advantage: • it overcomes the problem of unutilized space in linear queues, when it is implemented as array.
  • 15. OPERATIONS OF CIRCULAR QUEUE • To perform the insertion operation in the circular queue , the position of the element is calculated by the relation as, Rear = ( Rear + 1) % MaxSize Queue [ Rear ] = Value To perform the deletion operation , the position of the Front pointer is calculated by the relation, Value = Cqueue[Front]; Front = (Front +1) % MaxSize;
  • 16. INSERTION void Cenqueue ( int X ) { if ( Front == (Rear + 1) % MaxSize print ( “ Queue is Overflow “ ); else { if ( Front == -1) Front = Rear = 0; else Rear = ( Rear + 1) % MaxSize; Cqueue [ Rear ] = X; } }
  • 17. DELETION Int Dequeue ( ) { if ( front = = - 1) print ( “ Queue is underflow “ ); else { X = Cqueue [Front]; if ( Front = = Rear ) Front = Rear = – 1; else Front = (Front + 1) % MaxSize; } return (X); }
  • 18. PRIORITY QUEUE • Insertion and deletion can be performed in any position of the queue based on some priority. • An element with higher priority is processed before an element with a lower priority. • Two elements with the same priority are processed on a first-come-first- served (FCFS) basis. • Used to sort the elements using heap sort.
  • 19. APPLICATIONS OF QUEUE • Batch Processing in operating systems • Simulation • Queueing theory • Computer Networks