SlideShare a Scribd company logo
5.Queue
Definition of Queue
• A Queue is an ordered collection of items in
which items are deleted from one end called
the front and items are inserted from other
end called rear.
• The elements are inserted and deleted in FIFO
manner.
Front=-1 , Rear=-1
Queue
Types of Queue
1. Circular Queue.
2. Priority Queue.
3. DeQue
4
Drawback of Linear Queue
• Once the queue is full, even though few elements from the front are deleted and
some occupied space is relieved, it is not possible to add anymore new elements,
as the rear has already reached the Queue’s rear most position.
Circular Queue
• This queue is not linear but circular.
• Its structure can be like the following figure:
Figure: Circular Queue having
Rear = 5 and Front = 0
• In circular queue, once the Queue is full the
"First" element of the Queue becomes the
"Rear" most element, if and only if the "Front"
has moved forward. otherwise it will again be
a "Queue overflow" state.
5
Example: Consider the following circular queue with N = 5.
1. Initially, Rear = 0, Front = 0.
2. Insert 10, Rear = 1, Front = 1.
3. Insert 50, Rear = 2, Front = 1.
4. Insert 20, Rear = 3, Front = 0.
5. Insert 70, Rear = 4, Front = 1.
6. Delete front, Rear = 4, Front = 2.
Rear
Rear
Rear
Rear
Rear
Front
Front
Front
Front
Front
Front=0
Rear=0
6
7. Insert 100, Rear = 5, Front = 2.
8. Insert 40, Rear = 1, Front = 2.
9. Insert 140, Rear = 1, Front = 2.
As Front = Rear + 1, so Queue overflow.
10. Delete front, Rear = 1, Front = 3.
Front
Rear
FrontRear
Rear
Rear
Front
Front
11. Delete front, Rear = 1, Front = 4.
12. Delete front, Rear = 1, Front = 5.
Rear
Rear
Front
Front
OPERATIONS AND ALGORITHMS OF CIRCULAR QUEUE:
1. Insert Operation:
Step 1: [Check for the Overflow]
If front = 1 and rear = n
Output “Overflow” and return
Step 2: [Insert element in the queue.]
Else if front = 0
front = 1
rear = 1
Q [rear] = value
Step 3: [Check if the rear at the end of the queue]
Else if rear = n
rear = 1
Q [rear] = value
Step 4: [insert the element]
Else
Rear = rear + 1
Q [rear] = value
Step 5: return
2. Delete Operation:
Step 1: [Check for underflow]
If front = 0
Output “Underflow” and return
Step 2: [Remove the element]
Value = Q [front]
Step 3: [Check whether the queue is empty or not]
If front = rear
front = 0
rear = 0
Step 4: [Check the front pointer position]
Else if front = n
front = 1
Else
front = front + 1
Step 5: [Return the removed element]
Return [value]
Priority Queues
• A Priority queue is a collection of elements
where each elements is assigned a priority.
1. An element of higher priority is processed
first.
2. Two elements with the same priority are
processed according to the order in which
they are added to queue.
e.g. Job Scheduling by OS.
• But should follow the FIFO concept.
• It can be a Ascending priority Queue or
Descending priority queue.
DEQues (Double Ended Queue)
• A Deque is a queue in which elements can be
inserted or deleted from any end. but not in
the middle.
• Four operations are possible on Deque.
1. Insert from front.
2. Insert from rear.
3. Delete from Front.
4. Delete from rear.
Reversing a stack using queue
1. Pop value from the stack.
2. Add that value to the queue.
3. Repeat step 1. till stack is not empty.
4. Delete a value from the queue and push it in
the same stack.
5. Repeat step 4. till queue is not empty.
Queue
Ad

More Related Content

What's hot (20)

Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURESStacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Insertion sort
Insertion sort Insertion sort
Insertion sort
Monalisa Patel
 
Queue ppt
Queue pptQueue ppt
Queue ppt
SouravKumar328
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
gomathi chlm
 
Stack
StackStack
Stack
Zaid Shabbir
 
Stack
StackStack
Stack
Seema Sharma
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
Dabbal Singh Mahara
 
Stack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data StructureStack & Queue using Linked List in Data Structure
Stack & Queue using Linked List in Data Structure
Meghaj Mallick
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Lovely Professional University
 
Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure Binary Heap Tree, Data Structure
Binary Heap Tree, Data Structure
Anand Ingle
 
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)
Self-Employed
 
Queue
QueueQueue
Queue
Raj Sarode
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptx
sandeep54552
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
ManishPrajapati78
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Shell sort
Shell sortShell sort
Shell sort
M Vishnuvardhan Reddy
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
Hossain Md Shakhawat
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver2
 
Queues
QueuesQueues
Queues
Lovely Professional University
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 

Viewers also liked (20)

Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
Roman Rodomansky
 
Queue
QueueQueue
Queue
Swarup Kumar Boro
 
Queue
QueueQueue
Queue
Nabeel Ahsen
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
23 stacks-queues-deques
23 stacks-queues-deques23 stacks-queues-deques
23 stacks-queues-deques
Rishabh Jindal
 
stack
stackstack
stack
Raj Sarode
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
Buxoo Abdullah
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
Farhanum Aziera
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
bca2010
 
Lists, queues and stacks
Lists, queues and stacksLists, queues and stacks
Lists, queues and stacks
ASU Online
 
Queue
QueueQueue
Queue
Zaid Shabbir
 
Dsa circular queue
Dsa circular queueDsa circular queue
Dsa circular queue
zzzubair
 
Stack & queues
Stack & queuesStack & queues
Stack & queues
pinakspatel
 
computer notes - Priority queue
computer notes -  Priority queuecomputer notes -  Priority queue
computer notes - Priority queue
ecomputernotes
 
23 priority queue
23 priority queue23 priority queue
23 priority queue
Godo Dodo
 
Circular queues
Circular queuesCircular queues
Circular queues
Ssankett Negi
 
Stack & queue
Stack & queueStack & queue
Stack & queue
Siddique Ibrahim
 
Heaps & priority queues
Heaps & priority queuesHeaps & priority queues
Heaps & priority queues
Pedro Hugo Valencia Morales
 
Stack and queue
Stack and queueStack and queue
Stack and queue
Shakila Mahjabin
 
Ad

Similar to Queue (20)

Queue
QueueQueue
Queue
Himadri Sen Gupta
 
Detalied information of queue
Detalied information of queueDetalied information of queue
Detalied information of queue
Smit Parikh
 
Queue
QueueQueue
Queue
Muhammad Farhan
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 
RPT_02_B_Queue presentation for FE students
RPT_02_B_Queue presentation for FE studentsRPT_02_B_Queue presentation for FE students
RPT_02_B_Queue presentation for FE students
AshishFamt
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
shaik faroq
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
MuhammadUmerIhtisham
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
Mandeep Singh
 
08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex
SadiaSharmin40
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
SherinRappai
 
queue (1).ppt queue notes and ppt in Data Structures
queue (1).ppt queue notes and ppt in Data Structuresqueue (1).ppt queue notes and ppt in Data Structures
queue (1).ppt queue notes and ppt in Data Structures
nisharaheja1986
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
Omprakash Chauhan
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
ArmanKhan382533
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
Ddushb
 
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
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Afaq Mansoor Khan
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
MattFlordeliza1
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
Victor Palmar
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
Soumen Santra
 
Queue data structures and operation on data structures
Queue data structures and operation on data structuresQueue data structures and operation on data structures
Queue data structures and operation on data structures
muskans14
 
Detalied information of queue
Detalied information of queueDetalied information of queue
Detalied information of queue
Smit Parikh
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 
RPT_02_B_Queue presentation for FE students
RPT_02_B_Queue presentation for FE studentsRPT_02_B_Queue presentation for FE students
RPT_02_B_Queue presentation for FE students
AshishFamt
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
shaik faroq
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
Mandeep Singh
 
08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex08_Queues.pptx showing how que works given vertex
08_Queues.pptx showing how que works given vertex
SadiaSharmin40
 
queue (1).ppt queue notes and ppt in Data Structures
queue (1).ppt queue notes and ppt in Data Structuresqueue (1).ppt queue notes and ppt in Data Structures
queue (1).ppt queue notes and ppt in Data Structures
nisharaheja1986
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
Omprakash Chauhan
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
Ddushb
 
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
 
Queue data structures and operation on data structures
Queue data structures and operation on data structuresQueue data structures and operation on data structures
Queue data structures and operation on data structures
muskans14
 
Ad

Recently uploaded (20)

Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...Classification of mental disorder in 5th semester bsc. nursing and also used ...
Classification of mental disorder in 5th semester bsc. nursing and also used ...
parmarjuli1412
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 

Queue

  • 2. Definition of Queue • A Queue is an ordered collection of items in which items are deleted from one end called the front and items are inserted from other end called rear. • The elements are inserted and deleted in FIFO manner. Front=-1 , Rear=-1 Queue
  • 3. Types of Queue 1. Circular Queue. 2. Priority Queue. 3. DeQue
  • 4. 4 Drawback of Linear Queue • Once the queue is full, even though few elements from the front are deleted and some occupied space is relieved, it is not possible to add anymore new elements, as the rear has already reached the Queue’s rear most position. Circular Queue • This queue is not linear but circular. • Its structure can be like the following figure: Figure: Circular Queue having Rear = 5 and Front = 0 • In circular queue, once the Queue is full the "First" element of the Queue becomes the "Rear" most element, if and only if the "Front" has moved forward. otherwise it will again be a "Queue overflow" state.
  • 5. 5 Example: Consider the following circular queue with N = 5. 1. Initially, Rear = 0, Front = 0. 2. Insert 10, Rear = 1, Front = 1. 3. Insert 50, Rear = 2, Front = 1. 4. Insert 20, Rear = 3, Front = 0. 5. Insert 70, Rear = 4, Front = 1. 6. Delete front, Rear = 4, Front = 2. Rear Rear Rear Rear Rear Front Front Front Front Front Front=0 Rear=0
  • 6. 6 7. Insert 100, Rear = 5, Front = 2. 8. Insert 40, Rear = 1, Front = 2. 9. Insert 140, Rear = 1, Front = 2. As Front = Rear + 1, so Queue overflow. 10. Delete front, Rear = 1, Front = 3. Front Rear FrontRear Rear Rear Front Front 11. Delete front, Rear = 1, Front = 4. 12. Delete front, Rear = 1, Front = 5. Rear Rear Front Front
  • 7. OPERATIONS AND ALGORITHMS OF CIRCULAR QUEUE: 1. Insert Operation: Step 1: [Check for the Overflow] If front = 1 and rear = n Output “Overflow” and return Step 2: [Insert element in the queue.] Else if front = 0 front = 1 rear = 1 Q [rear] = value Step 3: [Check if the rear at the end of the queue] Else if rear = n rear = 1 Q [rear] = value Step 4: [insert the element] Else Rear = rear + 1 Q [rear] = value Step 5: return
  • 8. 2. Delete Operation: Step 1: [Check for underflow] If front = 0 Output “Underflow” and return Step 2: [Remove the element] Value = Q [front] Step 3: [Check whether the queue is empty or not] If front = rear front = 0 rear = 0 Step 4: [Check the front pointer position] Else if front = n front = 1 Else front = front + 1 Step 5: [Return the removed element] Return [value]
  • 9. Priority Queues • A Priority queue is a collection of elements where each elements is assigned a priority. 1. An element of higher priority is processed first. 2. Two elements with the same priority are processed according to the order in which they are added to queue. e.g. Job Scheduling by OS.
  • 10. • But should follow the FIFO concept. • It can be a Ascending priority Queue or Descending priority queue.
  • 11. DEQues (Double Ended Queue) • A Deque is a queue in which elements can be inserted or deleted from any end. but not in the middle. • Four operations are possible on Deque. 1. Insert from front. 2. Insert from rear. 3. Delete from Front. 4. Delete from rear.
  • 12. Reversing a stack using queue 1. Pop value from the stack. 2. Add that value to the queue. 3. Repeat step 1. till stack is not empty. 4. Delete a value from the queue and push it in the same stack. 5. Repeat step 4. till queue is not empty.
  翻译: