SlideShare a Scribd company logo
1 of 21
Introduction To 
Algorithm
Abstract Data Type 
Stack & Queue is an example of ADT 
An array is not ADT.
Using a Queue 
Several example 
applications of queues are 
given in that Slides. 
This presentation describes 
the queue operations and 
two ways to implement a 
queue. 
Data Structures 
and Other Objects 
Using C++
What is Queue? 
A QUEUE IS A CONTAINER IN WHICH INSERTIONS 
ARE MADE ONLY AT THE BACK DELETIONS, 
RETRIEVALS, AND MODIFICATIONS ARE MADE 
ONLY AT THE FRONT.
The Queue Operations 
A queue is like a line of 
people waiting for a 
bank teller. The queue 
has a front and a rear. 
$ $ 
Front 
Rear
EnQueue Operations 
New people must enter the queue at 
the rear. The C++ queue class calls 
this a push, although it is usually 
called an enqueue operation. 
$ $ 
Front 
Rear
DeQueue Operations 
 When an item is taken from the queue, 
it always comes from the front. The C++ 
queue calls this a pop, although it is 
usually called a dequeue operation. 
$ $ 
Front 
Rear
Array Implementation 
A queue can be implemented with an array, as 
shown here. For example, this queue contains 
the integers 4 (at the front), 8 and 6 (at the rear). 
[[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] .. .. .. 
4 8 6 
AAnn aarrrraayy ooff iinntteeggeerrss ttoo 
iimmpplleemmeenntt aa qquueeuuee ooff 
iinntteeggeerrss 
WWee ddoonn''tt ccaarree wwhhaatt''ss iinn 
tthhiiss ppaarrtt ooff tthhee aarrrraayy..
Array Implementation 
The efficient implementation also keeps 
track of the number of items in the 
queue and the index of the first element 
(at the front of the queue), the last 
element (at the rear). 
[[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] .. .. .. 
4 8 6 
3 ssiizzee 
0 ffiirrsstt 
2 llaasstt
A Dequeue Operation 
When an element leaves the queue, 
size is decremented, and first 
changes, too. 
2 ssiizzee 
1 ffiirrsstt 
2 llaasstt 
[[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] .. .. .. 
4 8 6
An Enqueue Operation 
When an element enters the queue, 
size is incremented, and last changes, 
too. 
3 ssiizzee 
1 ffiirrsstt 
3 llaasstt 
[[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] .. .. .. 
8 6 2
At the End of the Array 
There is special behaviour at the end 
of the array. For example, suppose we 
want to add a new element to this 
queue, where the last index is [5]: 
2 
3 ssiizzee 
3 ffiirrsstt 
5 llaasstt 
[[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] 
5 6 1
At the End of the Array 
The new element goes at the front of 
the array (if that spot isn’t already 
used): 
4 ssiizzee 
3 ffiirrsstt 
0 llaasstt 
[[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] 
4 2 6 1
Array Queue Reviews 
 Easy to implement. 
 But it has a limited capacity with a fixed array 
 Special behaviour is needed when the rear 
reaches the end of the array. 
[[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] .. .. .. 
4 8 6 
3 ssiizzee 
0 ffiirrsstt 
2 llaasstt
Linked List Implementation 
A queue can also be 
implemented with a linked 
list with both a head and a 
tail pointer. 
null 
10 
15 
7 
13 
Head-ptr 
Tail-ptr
Linked List Implementation 
Which end do you think is the 
front of the queue? Why ? 
10 
15 
7 
13 
Head-ptr 
Tail-ptr 
null
Linked List Implementation 
The head-ptr points to the 
front of the list. 
Because it is harder to 
remove items from the tail 
of the list. 
Rear 
Front 
10 
15 
7 
13 
Head-ptr 
Tail-ptr 
null
The Queue Class 
template <class Item> 
class queue<Item> 
{ 
public: 
queue( ); 
void push(const Item& entry); 
void pop( ); 
bool empty( ) const; 
Item front( ) const; 
} 
 The C++ standard 
template library has a 
queue template class. 
 The template parameter 
is the type of the items 
that can be put in the 
queue.
Summary 
QQuueeuueess hhaavvee mmaannyy aapppplliiccaattiioonnss.. 
 IItteemmss eenntteerr aa qquueeuuee aatt tthhee rreeaarr aanndd 
lleeaavvee aa qquueeuuee aatt tthhee ffrroonntt.. 
QQuueeuueess ccaann bbee iimmpplleemmeenntteedd uussiinngg aann 
aarrrraayy oorr uussiinngg aa lliinnkkeedd lliisstt..
Daily Life Examples 
There's a queue of questions 
that you've asked in exam, all 
waiting for you to accept 
answers for them. 
Waiting in a queue in any 
bank for paying bills, depositing 
cash OR cheques.
Thank You 
THE END

More Related Content

What's hot (20)

My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Priority queue in DSA
Priority queue in DSAPriority queue in DSA
Priority queue in DSA
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Circular Queue data structure
Circular Queue data structureCircular Queue data structure
Circular Queue data structure
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
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
 
Stacks
StacksStacks
Stacks
 
Queue
QueueQueue
Queue
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Unit 2 linked list
Unit 2   linked listUnit 2   linked list
Unit 2 linked list
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 

Viewers also liked (20)

Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Notes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queueNotes DATA STRUCTURE - queue
Notes DATA STRUCTURE - queue
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Queue
QueueQueue
Queue
 
Stack
StackStack
Stack
 
Queue
QueueQueue
Queue
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Queue and stacks
Queue and stacksQueue and stacks
Queue and stacks
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
computer notes - Priority queue
computer notes -  Priority queuecomputer notes -  Priority queue
computer notes - Priority queue
 
Heaps & priority queues
Heaps & priority queuesHeaps & priority queues
Heaps & priority queues
 
Stack & queue
Stack & queueStack & queue
Stack & queue
 
stack
stackstack
stack
 
Priority queue
Priority queuePriority queue
Priority queue
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Linked List
Linked ListLinked List
Linked List
 

Similar to Queue

basics of queues
basics of queuesbasics of queues
basics of queuessirmanohar
 
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computerabinathsabi
 
Queue data structure
Queue data structureQueue data structure
Queue data structureMekk Mhmd
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbRAtna29
 
CEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdfCEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdfvtunali
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queueRai University
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queueRai University
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueRai University
 
Data structure.ppt
Data structure.pptData structure.ppt
Data structure.pptSajalFayyaz
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for publiciqbalphy1
 
Computer notes data structures - 9
Computer notes   data structures - 9Computer notes   data structures - 9
Computer notes data structures - 9ecomputernotes
 

Similar to Queue (20)

basics of queues
basics of queuesbasics of queues
basics of queues
 
Queue ADT for data structure for computer
Queue ADT for data structure for computerQueue ADT for data structure for computer
Queue ADT for data structure for computer
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
 
2 b queues
2 b queues2 b queues
2 b queues
 
CEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdfCEN 235 4. Abstract Data Types - Queue and Stack.pdf
CEN 235 4. Abstract Data Types - Queue and Stack.pdf
 
Queue
QueueQueue
Queue
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
Data structure.ppt
Data structure.pptData structure.ppt
Data structure.ppt
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
Queue
QueueQueue
Queue
 
05 queues
05 queues05 queues
05 queues
 
Unit 5 dsa QUEUE
Unit 5 dsa QUEUEUnit 5 dsa QUEUE
Unit 5 dsa QUEUE
 
Queues & ITS TYPES
Queues & ITS TYPESQueues & ITS TYPES
Queues & ITS TYPES
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Computer notes data structures - 9
Computer notes   data structures - 9Computer notes   data structures - 9
Computer notes data structures - 9
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 

Recently uploaded

Dutch Power - 26 maart 2024 - Henk Kras - Circular Plastics
Dutch Power - 26 maart 2024 - Henk Kras - Circular PlasticsDutch Power - 26 maart 2024 - Henk Kras - Circular Plastics
Dutch Power - 26 maart 2024 - Henk Kras - Circular PlasticsDutch Power
 
PHYSICS PROJECT BY MSC - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC  - NANOTECHNOLOGYPHYSICS PROJECT BY MSC  - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC - NANOTECHNOLOGYpruthirajnayak525
 
INDIAN GCP GUIDELINE. for Regulatory affair 1st sem CRR
INDIAN GCP GUIDELINE. for Regulatory  affair 1st sem CRRINDIAN GCP GUIDELINE. for Regulatory  affair 1st sem CRR
INDIAN GCP GUIDELINE. for Regulatory affair 1st sem CRRsarwankumar4524
 
Chizaram's Women Tech Makers Deck. .pptx
Chizaram's Women Tech Makers Deck.  .pptxChizaram's Women Tech Makers Deck.  .pptx
Chizaram's Women Tech Makers Deck. .pptxogubuikealex
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸mathanramanathan2005
 
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...漢銘 謝
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxJohnree4
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxmavinoikein
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSebastiano Panichella
 
Engaging Eid Ul Fitr Presentation for Kindergartners.pptx
Engaging Eid Ul Fitr Presentation for Kindergartners.pptxEngaging Eid Ul Fitr Presentation for Kindergartners.pptx
Engaging Eid Ul Fitr Presentation for Kindergartners.pptxAsifArshad8
 
miladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptxmiladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptxCarrieButtitta
 
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.KathleenAnnCordero2
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSebastiano Panichella
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationNathan Young
 
Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170Escort Service
 
Quality by design.. ppt for RA (1ST SEM
Quality by design.. ppt for  RA (1ST SEMQuality by design.. ppt for  RA (1ST SEM
Quality by design.. ppt for RA (1ST SEMCharmi13
 
DGT @ CTAC 2024 Valencia: Most crucial invest to digitalisation_Sven Zoelle_v...
DGT @ CTAC 2024 Valencia: Most crucial invest to digitalisation_Sven Zoelle_v...DGT @ CTAC 2024 Valencia: Most crucial invest to digitalisation_Sven Zoelle_v...
DGT @ CTAC 2024 Valencia: Most crucial invest to digitalisation_Sven Zoelle_v...Henrik Hanke
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringSebastiano Panichella
 
RACHEL-ANN M. TENIBRO PRODUCT RESEARCH PRESENTATION
RACHEL-ANN M. TENIBRO PRODUCT RESEARCH PRESENTATIONRACHEL-ANN M. TENIBRO PRODUCT RESEARCH PRESENTATION
RACHEL-ANN M. TENIBRO PRODUCT RESEARCH PRESENTATIONRachelAnnTenibroAmaz
 
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.comSaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.comsaastr
 

Recently uploaded (20)

Dutch Power - 26 maart 2024 - Henk Kras - Circular Plastics
Dutch Power - 26 maart 2024 - Henk Kras - Circular PlasticsDutch Power - 26 maart 2024 - Henk Kras - Circular Plastics
Dutch Power - 26 maart 2024 - Henk Kras - Circular Plastics
 
PHYSICS PROJECT BY MSC - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC  - NANOTECHNOLOGYPHYSICS PROJECT BY MSC  - NANOTECHNOLOGY
PHYSICS PROJECT BY MSC - NANOTECHNOLOGY
 
INDIAN GCP GUIDELINE. for Regulatory affair 1st sem CRR
INDIAN GCP GUIDELINE. for Regulatory  affair 1st sem CRRINDIAN GCP GUIDELINE. for Regulatory  affair 1st sem CRR
INDIAN GCP GUIDELINE. for Regulatory affair 1st sem CRR
 
Chizaram's Women Tech Makers Deck. .pptx
Chizaram's Women Tech Makers Deck.  .pptxChizaram's Women Tech Makers Deck.  .pptx
Chizaram's Women Tech Makers Deck. .pptx
 
Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸Mathan flower ppt.pptx slide orchids ✨🌸
Mathan flower ppt.pptx slide orchids ✨🌸
 
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
THE COUNTRY WHO SOLVED THE WORLD_HOW CHINA LAUNCHED THE CIVILIZATION REVOLUTI...
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptx
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptx
 
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
 
Engaging Eid Ul Fitr Presentation for Kindergartners.pptx
Engaging Eid Ul Fitr Presentation for Kindergartners.pptxEngaging Eid Ul Fitr Presentation for Kindergartners.pptx
Engaging Eid Ul Fitr Presentation for Kindergartners.pptx
 
miladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptxmiladyskindiseases-200705210221 2.!!pptx
miladyskindiseases-200705210221 2.!!pptx
 
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.
PAG-UNLAD NG EKONOMIYA na dapat isaalang alang sa pag-aaral.
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation Track
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism Presentation
 
Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170Call Girls In Aerocity 🤳 Call Us +919599264170
Call Girls In Aerocity 🤳 Call Us +919599264170
 
Quality by design.. ppt for RA (1ST SEM
Quality by design.. ppt for  RA (1ST SEMQuality by design.. ppt for  RA (1ST SEM
Quality by design.. ppt for RA (1ST SEM
 
DGT @ CTAC 2024 Valencia: Most crucial invest to digitalisation_Sven Zoelle_v...
DGT @ CTAC 2024 Valencia: Most crucial invest to digitalisation_Sven Zoelle_v...DGT @ CTAC 2024 Valencia: Most crucial invest to digitalisation_Sven Zoelle_v...
DGT @ CTAC 2024 Valencia: Most crucial invest to digitalisation_Sven Zoelle_v...
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software Engineering
 
RACHEL-ANN M. TENIBRO PRODUCT RESEARCH PRESENTATION
RACHEL-ANN M. TENIBRO PRODUCT RESEARCH PRESENTATIONRACHEL-ANN M. TENIBRO PRODUCT RESEARCH PRESENTATION
RACHEL-ANN M. TENIBRO PRODUCT RESEARCH PRESENTATION
 
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.comSaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
SaaStr Workshop Wednesday w/ Kyle Norton, Owner.com
 

Queue

  • 2. Abstract Data Type Stack & Queue is an example of ADT An array is not ADT.
  • 3. Using a Queue Several example applications of queues are given in that Slides. This presentation describes the queue operations and two ways to implement a queue. Data Structures and Other Objects Using C++
  • 4. What is Queue? A QUEUE IS A CONTAINER IN WHICH INSERTIONS ARE MADE ONLY AT THE BACK DELETIONS, RETRIEVALS, AND MODIFICATIONS ARE MADE ONLY AT THE FRONT.
  • 5. The Queue Operations A queue is like a line of people waiting for a bank teller. The queue has a front and a rear. $ $ Front Rear
  • 6. EnQueue Operations New people must enter the queue at the rear. The C++ queue class calls this a push, although it is usually called an enqueue operation. $ $ Front Rear
  • 7. DeQueue Operations  When an item is taken from the queue, it always comes from the front. The C++ queue calls this a pop, although it is usually called a dequeue operation. $ $ Front Rear
  • 8. Array Implementation A queue can be implemented with an array, as shown here. For example, this queue contains the integers 4 (at the front), 8 and 6 (at the rear). [[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] .. .. .. 4 8 6 AAnn aarrrraayy ooff iinntteeggeerrss ttoo iimmpplleemmeenntt aa qquueeuuee ooff iinntteeggeerrss WWee ddoonn''tt ccaarree wwhhaatt''ss iinn tthhiiss ppaarrtt ooff tthhee aarrrraayy..
  • 9. Array Implementation The efficient implementation also keeps track of the number of items in the queue and the index of the first element (at the front of the queue), the last element (at the rear). [[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] .. .. .. 4 8 6 3 ssiizzee 0 ffiirrsstt 2 llaasstt
  • 10. A Dequeue Operation When an element leaves the queue, size is decremented, and first changes, too. 2 ssiizzee 1 ffiirrsstt 2 llaasstt [[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] .. .. .. 4 8 6
  • 11. An Enqueue Operation When an element enters the queue, size is incremented, and last changes, too. 3 ssiizzee 1 ffiirrsstt 3 llaasstt [[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] .. .. .. 8 6 2
  • 12. At the End of the Array There is special behaviour at the end of the array. For example, suppose we want to add a new element to this queue, where the last index is [5]: 2 3 ssiizzee 3 ffiirrsstt 5 llaasstt [[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] 5 6 1
  • 13. At the End of the Array The new element goes at the front of the array (if that spot isn’t already used): 4 ssiizzee 3 ffiirrsstt 0 llaasstt [[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] 4 2 6 1
  • 14. Array Queue Reviews  Easy to implement.  But it has a limited capacity with a fixed array  Special behaviour is needed when the rear reaches the end of the array. [[ 00 ]] [[11]] [[ 22 ]] [[ 33 ]] [[ 44 ]] [[ 55 ]] .. .. .. 4 8 6 3 ssiizzee 0 ffiirrsstt 2 llaasstt
  • 15. Linked List Implementation A queue can also be implemented with a linked list with both a head and a tail pointer. null 10 15 7 13 Head-ptr Tail-ptr
  • 16. Linked List Implementation Which end do you think is the front of the queue? Why ? 10 15 7 13 Head-ptr Tail-ptr null
  • 17. Linked List Implementation The head-ptr points to the front of the list. Because it is harder to remove items from the tail of the list. Rear Front 10 15 7 13 Head-ptr Tail-ptr null
  • 18. The Queue Class template <class Item> class queue<Item> { public: queue( ); void push(const Item& entry); void pop( ); bool empty( ) const; Item front( ) const; }  The C++ standard template library has a queue template class.  The template parameter is the type of the items that can be put in the queue.
  • 19. Summary QQuueeuueess hhaavvee mmaannyy aapppplliiccaattiioonnss..  IItteemmss eenntteerr aa qquueeuuee aatt tthhee rreeaarr aanndd lleeaavvee aa qquueeuuee aatt tthhee ffrroonntt.. QQuueeuueess ccaann bbee iimmpplleemmeenntteedd uussiinngg aann aarrrraayy oorr uussiinngg aa lliinnkkeedd lliisstt..
  • 20. Daily Life Examples There's a queue of questions that you've asked in exam, all waiting for you to accept answers for them. Waiting in a queue in any bank for paying bills, depositing cash OR cheques.

Editor's Notes

  1. When you think of a computer science queue, you can imagine a line of people waiting for a teller in a bank. The line has a front (the next person to be served) and a rear (the last person to arrive.
  2. This lecture introduces queues. The presentation also shows two common ways of implementing a queue of integers.
  3. When you think of a computer science queue, you can imagine a line of people waiting for a teller in a bank. The line has a front (the next person to be served) and a rear (the last person to arrive.
  4. When you think of a computer science queue, you can imagine a line of people waiting for a teller in a bank. The line has a front (the next person to be served) and a rear (the last person to arrive.
  5. Don’t ask me why the C++ STL used the name push. It only confuses matters with a stack. In any case, when a new item enters a queue, it does so at the rear.
  6. When an item is removed from a queue, the removal occurs at the front.
  7. Just like our stack implementation in the previous chapter, one way to implement a queue is to store the elements in an array.
  8. The easiest implementation also keeps track of three numbers. The size could be as small as zero or as large as the number of items in the array. The index of the front element is stored in the first member variable. The front item in the queue is at that index of the array. The next item is after the first one and so on until the rear of the queue that occurs at the index stored in a member variable called last.
  9. This shows how the member variables change when an item leaves the queue.
  10. And this shows how the member variables change when a new item enters the queue. For a fixed size array, a new item may enter only if the current size of the queue is less than the size of the array. For a dynamic array, we could increase the size of the array when the queue grows beyond the current array size.
  11. An array implementation of a queue must have special behavior when the rear of the queue reaches the end of the array. In this example, suppose we want to add the number 4 to the queue. We can do so…
  12. …by putting it at location 0 (if that location is not already used).
  13. Here are some of the key aspects of an array implementation of a queue.
  14. A linked list can also be used to implement a queue, but we must maintain both a head and a tail pointer because we need access to both the front and the rear of the queue.
  15. Does it matter which end of a singly-linked list we use for the front of the queue?
  16. Of course, we could put the front of the queue at the end of the linked list, but it would be hard to remove an item. Do you see why?
  17. These are the four most common queue operations. The empty function tells you whether the queue has any items at the moment. The front operation returns the item at the front of the queue (without removing it from the queue).
  18. A quick summary . . .
  19. Feel free to send your ideas to: Michael Main [email_address]