ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Chapter Contents 8.1 Introduction to Queues 8.2 Designing and Building a Queue Class – Array Based 8.3 Linked Queues 8.4 Application of Queues: Buffers and Scheduling 8.5 Case Study: Center Simulation Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Chapter Objectives To study a queue as an ADT Build a static-array-based implementation of queues Build a dynamic-array-based implementation of queues Show how queues are used in I/O buffers and scheduling in a computer system (Optional) See how queues are used in simulations of phenomena that involve waiting in lines Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Introduction to Queues  A queue is a waiting line – seen in daily life A line of people waiting for a bank teller A line of cars at a toll both "This is the captain, we're 5 th  in line for takeoff"  What other kinds of queues can you think of Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
The Queue As an ADT A queue is a sequence of data elements In the sequence Items can be removed only at the front Items can be added only at the other end, the back Basic operations Construct a queue Check if empty Enqueue (add element to back) Front (retrieve value of element from front) Dequeue (remove element from front) Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Designing and Building a Queue Class  Array-Based Consider an array in which to store a queue Note additional variables needed myFront, myBack Picture a queue object like this Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Designing and Building a Queue Class  Array-Based Problems We quickly "walk off the end" of the array Possible solutions Shift array elements Use a circular queue Note that both empty and full queue gives  myBack == myFront Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Designing and Building a Queue Class  Array-Based Using a static array QUEUE_CAPACITY  specified Enqueue increments  myBack  using mod operator, checks for full queue Dequeue increments  myFront  using mod operator, checks for empty queue Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Using Dynamic Array to Store Queue Elements Similar problems as with list and stack Fixed size array can be specified too large or too small Dynamic array design allows sizing of array for multiple situations Results in structure as shown myCapacity determined at run time Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Linked Queues Even with dynamic allocation of queue size Array size is still fixed Cannot be adjusted during run of program Could use linked list to store queue elements Can grow and shrink to fit the situation No need for upper bound ( myCapacity ) Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Linked Queues Constructor initializes  myFront ,  myBack Front return myFront->data Dequeue Delete first node (watch for empty queue) Enqueue Insert node at end of list Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Circular Linked List Possible to treat the linked list as circular Last node points back to first node Alternatively keep pointer to last node rather than first node Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Application of Queues: Buffers and Scheduling Important use of queues is I/O scheduling Use buffers in memory to improve program execution Buffer arranged in FIFO  structure Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Application of Queues: Buffers and Scheduling Consider a keyboard buffer Acts as a queue But elements may be  removed from the back of  the queue with  backspace key A printer spool is a queue of print jobs Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Application of Queues: Buffers and Scheduling Queues used to schedule tasks within an operating  system Job moves from disk to ready queue Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Application of Queues: Buffers and Scheduling Ready queue may actually be a  priority  queue … job may get to "cut the line" based on its priority Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Case Study: Information Center Simulation Most waiting lines (queues) are dynamic Their lengths grow and shrink over time Simulation models this dynamic process Enables study of the behavior of the process Modeled with one or more equations Queue behavior involves randomness We will use pseudo random number generator Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Problem Analysis and Specification Consider an information center  Calls arrive at random intervals Placed in queue of incoming calls When agent becomes available, services call at front of queue We will simulate receipt of "calls" for some number of "minutes" we keep track of calls in the queue Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Problem Analysis and Specification Input to the simulation program Time limit Arrival rate of calls Distribution of service times Desired output Number of calls processed Average waiting time per call Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Problem Analysis and Specification Constructor Initialize input data members myTimer ,  myIncomingCalls  initialized by their constructors The  run()   method Starts and manages simulation The  checkForNewCall()   method Random number generated, compared to myArrivalRate If new call has arrived, create new Call object, place in queue Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
Problem Analysis and Specification The  service()   method Checks time remaining for current call When done, retrieves and starts up next call from front of queue The  display()   method Report generated at end of simulation Reference the  Timer  class and  Call  class used in the  Simulation  class Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3

More Related Content

What's hot (8)

Queues
QueuesQueues
Queues
maamir farooq
Ìý
Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
Aspect-oriented programming with AspectJ (as part of the the PTT lecture)Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
Ralf Laemmel
Ìý
Hadoop for Data Science: Moving from BI dashboards to R models, using Hive st...
Hadoop for Data Science: Moving from BI dashboards to R models, using Hive st...Hadoop for Data Science: Moving from BI dashboards to R models, using Hive st...
Hadoop for Data Science: Moving from BI dashboards to R models, using Hive st...
huguk
Ìý
Matlab Presentation
Matlab PresentationMatlab Presentation
Matlab Presentation
Mohamed El Rayany
Ìý
An adaptive algorithm for detection of duplicate records
An adaptive algorithm for detection of duplicate recordsAn adaptive algorithm for detection of duplicate records
An adaptive algorithm for detection of duplicate records
Likan Patra
Ìý
La programmation concurrente par flux de données
La programmation concurrente par flux de donnéesLa programmation concurrente par flux de données
La programmation concurrente par flux de données
Microsoft
Ìý
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithms
guest084d20
Ìý
Apriori algorithm
Apriori algorithmApriori algorithm
Apriori algorithm
Junghoon Kim
Ìý
Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
Aspect-oriented programming with AspectJ (as part of the the PTT lecture)Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
Aspect-oriented programming with AspectJ (as part of the the PTT lecture)
Ralf Laemmel
Ìý
Hadoop for Data Science: Moving from BI dashboards to R models, using Hive st...
Hadoop for Data Science: Moving from BI dashboards to R models, using Hive st...Hadoop for Data Science: Moving from BI dashboards to R models, using Hive st...
Hadoop for Data Science: Moving from BI dashboards to R models, using Hive st...
huguk
Ìý
An adaptive algorithm for detection of duplicate records
An adaptive algorithm for detection of duplicate recordsAn adaptive algorithm for detection of duplicate records
An adaptive algorithm for detection of duplicate records
Likan Patra
Ìý
La programmation concurrente par flux de données
La programmation concurrente par flux de donnéesLa programmation concurrente par flux de données
La programmation concurrente par flux de données
Microsoft
Ìý
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithms
guest084d20
Ìý
Apriori algorithm
Apriori algorithmApriori algorithm
Apriori algorithm
Junghoon Kim
Ìý

Similar to Lec8 (20)

Lec4
Lec4Lec4
Lec4
Saad Gabr
Ìý
Lec5
Lec5Lec5
Lec5
Saad Gabr
Ìý
Lec3
Lec3Lec3
Lec3
Ibrahim El-Torbany
Ìý
Lesson 4 stacks and queues
Lesson 4  stacks and queuesLesson 4  stacks and queues
Lesson 4 stacks and queues
MLG College of Learning, Inc
Ìý
Lec4
Lec4Lec4
Lec4
Ibrahim El-Torbany
Ìý
Tree
TreeTree
Tree
guest917885e
Ìý
Tree
TreeTree
Tree
guest917885e
Ìý
The presention is about the queue data structure
The presention is about the queue data structureThe presention is about the queue data structure
The presention is about the queue data structure
gaurav77712
Ìý
QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)
Mehedi Hasan
Ìý
5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil
widespreadpromotion
Ìý
autoTVM
autoTVMautoTVM
autoTVM
Yi-Wen Hung
Ìý
PLP-L1-Intro.ppt
PLP-L1-Intro.pptPLP-L1-Intro.ppt
PLP-L1-Intro.ppt
VaibhavPearson
Ìý
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
Muhazzab Chouhadry
Ìý
R Cheat Sheet
R Cheat SheetR Cheat Sheet
R Cheat Sheet
Dr. Volkan OBAN
Ìý
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
RAtna29
Ìý
Georgia Tech: Performance Engineering - Queuing Theory and Predictive Modeling
Georgia Tech: Performance Engineering - Queuing Theory and Predictive ModelingGeorgia Tech: Performance Engineering - Queuing Theory and Predictive Modeling
Georgia Tech: Performance Engineering - Queuing Theory and Predictive Modeling
Brian Wilson
Ìý
Accelerating the Development of Efficient CP Optimizer Models
Accelerating the Development of Efficient CP Optimizer ModelsAccelerating the Development of Efficient CP Optimizer Models
Accelerating the Development of Efficient CP Optimizer Models
Philippe Laborie
Ìý
RapidRma
RapidRmaRapidRma
RapidRma
CS, NcState
Ìý
Array 1D.................................pptx
Array 1D.................................pptxArray 1D.................................pptx
Array 1D.................................pptx
Hassan Kamal
Ìý
7-DSA- Queue.pptx in detail for students
7-DSA- Queue.pptx in detail for students7-DSA- Queue.pptx in detail for students
7-DSA- Queue.pptx in detail for students
us86123456789
Ìý
The presention is about the queue data structure
The presention is about the queue data structureThe presention is about the queue data structure
The presention is about the queue data structure
gaurav77712
Ìý
QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)QUEUE in data-structure (classification, working procedure, Applications)
QUEUE in data-structure (classification, working procedure, Applications)
Mehedi Hasan
Ìý
5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil5. Queue - Data Structures using C++ by Varsha Patil
5. Queue - Data Structures using C++ by Varsha Patil
widespreadpromotion
Ìý
PLP-L1-Intro.ppt
PLP-L1-Intro.pptPLP-L1-Intro.ppt
PLP-L1-Intro.ppt
VaibhavPearson
Ìý
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
RAtna29
Ìý
Georgia Tech: Performance Engineering - Queuing Theory and Predictive Modeling
Georgia Tech: Performance Engineering - Queuing Theory and Predictive ModelingGeorgia Tech: Performance Engineering - Queuing Theory and Predictive Modeling
Georgia Tech: Performance Engineering - Queuing Theory and Predictive Modeling
Brian Wilson
Ìý
Accelerating the Development of Efficient CP Optimizer Models
Accelerating the Development of Efficient CP Optimizer ModelsAccelerating the Development of Efficient CP Optimizer Models
Accelerating the Development of Efficient CP Optimizer Models
Philippe Laborie
Ìý
Array 1D.................................pptx
Array 1D.................................pptxArray 1D.................................pptx
Array 1D.................................pptx
Hassan Kamal
Ìý
7-DSA- Queue.pptx in detail for students
7-DSA- Queue.pptx in detail for students7-DSA- Queue.pptx in detail for students
7-DSA- Queue.pptx in detail for students
us86123456789
Ìý

More from Saad Gabr (10)

Ch5
Ch5Ch5
Ch5
Saad Gabr
Ìý
Ch3
Ch3Ch3
Ch3
Saad Gabr
Ìý
Ch2
Ch2Ch2
Ch2
Saad Gabr
Ìý
Ch1
Ch1Ch1
Ch1
Saad Gabr
Ìý
Ch4
Ch4Ch4
Ch4
Saad Gabr
Ìý
02 20110314-simulation
02 20110314-simulation02 20110314-simulation
02 20110314-simulation
Saad Gabr
Ìý
Lec6 mod linked list
Lec6 mod linked listLec6 mod linked list
Lec6 mod linked list
Saad Gabr
Ìý
Lec2
Lec2Lec2
Lec2
Saad Gabr
Ìý
Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
Saad Gabr
Ìý
Lec1
Lec1Lec1
Lec1
Saad Gabr
Ìý
02 20110314-simulation
02 20110314-simulation02 20110314-simulation
02 20110314-simulation
Saad Gabr
Ìý
Lec6 mod linked list
Lec6 mod linked listLec6 mod linked list
Lec6 mod linked list
Saad Gabr
Ìý
Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
Saad Gabr
Ìý

Recently uploaded (20)

TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptxTLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
RizaBedayo
Ìý
Kaun TALHA quiz Prelims - El Dorado 2025
Kaun TALHA quiz Prelims - El Dorado 2025Kaun TALHA quiz Prelims - El Dorado 2025
Kaun TALHA quiz Prelims - El Dorado 2025
Conquiztadors- the Quiz Society of Sri Venkateswara College
Ìý
Fuel part 1.pptx........................
Fuel part 1.pptx........................Fuel part 1.pptx........................
Fuel part 1.pptx........................
ksbhattadcm
Ìý
Adventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil SirAdventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil Sir
GUJARATCOMMERCECOLLE
Ìý
How to Manage Putaway Rule in Odoo 17 Inventory
How to Manage Putaway Rule in Odoo 17 InventoryHow to Manage Putaway Rule in Odoo 17 Inventory
How to Manage Putaway Rule in Odoo 17 Inventory
Celine George
Ìý
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣsHow to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
Celine George
Ìý
Reordering Rules in Odoo 17 Inventory - Odoo ºÝºÝߣs
Reordering Rules in Odoo 17 Inventory - Odoo ºÝºÝߣsReordering Rules in Odoo 17 Inventory - Odoo ºÝºÝߣs
Reordering Rules in Odoo 17 Inventory - Odoo ºÝºÝߣs
Celine George
Ìý
Computer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network LayerComputer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network Layer
Murugan146644
Ìý
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir DotanThe Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
History of Stoke Newington
Ìý
Storytelling instructions...............
Storytelling instructions...............Storytelling instructions...............
Storytelling instructions...............
Alexander Benito
Ìý
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
Ìý
TPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategyTPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategy
Henry Tapper
Ìý
Essentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok SonawalaEssentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok Sonawala
Association for Project Management
Ìý
How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George
Ìý
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptxFESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
DanmarieMuli1
Ìý
The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .
saanidhyapatel09
Ìý
Research & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptxResearch & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptx
Dr. Sarita Anand
Ìý
Digital Tools with AI for e-Content Development.pptx
Digital Tools with AI for e-Content Development.pptxDigital Tools with AI for e-Content Development.pptx
Digital Tools with AI for e-Content Development.pptx
Dr. Sarita Anand
Ìý
EDL 290F Week 3 - Mountaintop Views (2025).pdf
EDL 290F Week 3  - Mountaintop Views (2025).pdfEDL 290F Week 3  - Mountaintop Views (2025).pdf
EDL 290F Week 3 - Mountaintop Views (2025).pdf
Liz Walsh-Trevino
Ìý
How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18
Celine George
Ìý
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptxTLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
RizaBedayo
Ìý
Fuel part 1.pptx........................
Fuel part 1.pptx........................Fuel part 1.pptx........................
Fuel part 1.pptx........................
ksbhattadcm
Ìý
Adventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil SirAdventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil Sir
GUJARATCOMMERCECOLLE
Ìý
How to Manage Putaway Rule in Odoo 17 Inventory
How to Manage Putaway Rule in Odoo 17 InventoryHow to Manage Putaway Rule in Odoo 17 Inventory
How to Manage Putaway Rule in Odoo 17 Inventory
Celine George
Ìý
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣsHow to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
Celine George
Ìý
Reordering Rules in Odoo 17 Inventory - Odoo ºÝºÝߣs
Reordering Rules in Odoo 17 Inventory - Odoo ºÝºÝߣsReordering Rules in Odoo 17 Inventory - Odoo ºÝºÝߣs
Reordering Rules in Odoo 17 Inventory - Odoo ºÝºÝߣs
Celine George
Ìý
Computer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network LayerComputer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network Layer
Murugan146644
Ìý
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir DotanThe Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
History of Stoke Newington
Ìý
Storytelling instructions...............
Storytelling instructions...............Storytelling instructions...............
Storytelling instructions...............
Alexander Benito
Ìý
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
Ìý
TPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategyTPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategy
Henry Tapper
Ìý
How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George
Ìý
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptxFESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
DanmarieMuli1
Ìý
The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .
saanidhyapatel09
Ìý
Research & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptxResearch & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptx
Dr. Sarita Anand
Ìý
Digital Tools with AI for e-Content Development.pptx
Digital Tools with AI for e-Content Development.pptxDigital Tools with AI for e-Content Development.pptx
Digital Tools with AI for e-Content Development.pptx
Dr. Sarita Anand
Ìý
EDL 290F Week 3 - Mountaintop Views (2025).pdf
EDL 290F Week 3  - Mountaintop Views (2025).pdfEDL 290F Week 3  - Mountaintop Views (2025).pdf
EDL 290F Week 3 - Mountaintop Views (2025).pdf
Liz Walsh-Trevino
Ìý
How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18
Celine George
Ìý

Lec8

  • 1. Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 2. Chapter Contents 8.1 Introduction to Queues 8.2 Designing and Building a Queue Class – Array Based 8.3 Linked Queues 8.4 Application of Queues: Buffers and Scheduling 8.5 Case Study: Center Simulation Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 3. Chapter Objectives To study a queue as an ADT Build a static-array-based implementation of queues Build a dynamic-array-based implementation of queues Show how queues are used in I/O buffers and scheduling in a computer system (Optional) See how queues are used in simulations of phenomena that involve waiting in lines Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 4. Introduction to Queues A queue is a waiting line – seen in daily life A line of people waiting for a bank teller A line of cars at a toll both "This is the captain, we're 5 th in line for takeoff" What other kinds of queues can you think of Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 5. The Queue As an ADT A queue is a sequence of data elements In the sequence Items can be removed only at the front Items can be added only at the other end, the back Basic operations Construct a queue Check if empty Enqueue (add element to back) Front (retrieve value of element from front) Dequeue (remove element from front) Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 6. Designing and Building a Queue Class Array-Based Consider an array in which to store a queue Note additional variables needed myFront, myBack Picture a queue object like this Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 7. Designing and Building a Queue Class Array-Based Problems We quickly "walk off the end" of the array Possible solutions Shift array elements Use a circular queue Note that both empty and full queue gives myBack == myFront Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 8. Designing and Building a Queue Class Array-Based Using a static array QUEUE_CAPACITY specified Enqueue increments myBack using mod operator, checks for full queue Dequeue increments myFront using mod operator, checks for empty queue Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 9. Using Dynamic Array to Store Queue Elements Similar problems as with list and stack Fixed size array can be specified too large or too small Dynamic array design allows sizing of array for multiple situations Results in structure as shown myCapacity determined at run time Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 10. Linked Queues Even with dynamic allocation of queue size Array size is still fixed Cannot be adjusted during run of program Could use linked list to store queue elements Can grow and shrink to fit the situation No need for upper bound ( myCapacity ) Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 11. Linked Queues Constructor initializes myFront , myBack Front return myFront->data Dequeue Delete first node (watch for empty queue) Enqueue Insert node at end of list Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 12. Circular Linked List Possible to treat the linked list as circular Last node points back to first node Alternatively keep pointer to last node rather than first node Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 13. Application of Queues: Buffers and Scheduling Important use of queues is I/O scheduling Use buffers in memory to improve program execution Buffer arranged in FIFO structure Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 14. Application of Queues: Buffers and Scheduling Consider a keyboard buffer Acts as a queue But elements may be removed from the back of the queue with backspace key A printer spool is a queue of print jobs Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 15. Application of Queues: Buffers and Scheduling Queues used to schedule tasks within an operating system Job moves from disk to ready queue Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 16. Application of Queues: Buffers and Scheduling Ready queue may actually be a priority queue … job may get to "cut the line" based on its priority Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 17. Case Study: Information Center Simulation Most waiting lines (queues) are dynamic Their lengths grow and shrink over time Simulation models this dynamic process Enables study of the behavior of the process Modeled with one or more equations Queue behavior involves randomness We will use pseudo random number generator Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 18. Problem Analysis and Specification Consider an information center Calls arrive at random intervals Placed in queue of incoming calls When agent becomes available, services call at front of queue We will simulate receipt of "calls" for some number of "minutes" we keep track of calls in the queue Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 19. Problem Analysis and Specification Input to the simulation program Time limit Arrival rate of calls Distribution of service times Desired output Number of calls processed Average waiting time per call Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 20. Problem Analysis and Specification Constructor Initialize input data members myTimer , myIncomingCalls initialized by their constructors The run() method Starts and manages simulation The checkForNewCall() method Random number generated, compared to myArrivalRate If new call has arrived, create new Call object, place in queue Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3
  • 21. Problem Analysis and Specification The service() method Checks time remaining for current call When done, retrieves and starts up next call from front of queue The display() method Report generated at end of simulation Reference the Timer class and Call class used in the Simulation class Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved. 0-13-140909-3