Queues Deques and Priority Queues Chapter 10 Data
- Slides: 48
Queues, Deques, and Priority Queues Chapter 10 Data Structures and Abstractions with Java, 4 e, Global Edition Frank Carrano © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Queue • A queue is another name for a waiting line • Used within operating systems and to simulate real-world events § Come into play whenever processes or events must wait • Entries organized first-in, first-out © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Queue FIGURE 10 -1 Some everyday queues © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Queue • Terminology § Item added first, or earliest, is at the front of the queue § Item added most recently is at the back of the queue • Additions to a software queue must occur at its back • Client can look at or remove only the entry at the front of the queue © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Queue © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Queue © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Queue LISTING 10 -1 An interface for the ADT queue © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Queue FIGURE 10 -2 A queue of strings after (a) enqueue adds Jim; (b) enqueue adds Jess; (c) enqueue adds Jill; (d) enqueue adds Jane; © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Queue FIGURE 10 -2 A queue of strings after (e) enqueue adds Joe; (f) dequeue retrieves and removes Jim; (g) enqueue adds Jerry; (h) dequeue retrieves and removes Jess © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line FIGURE 10 -3 A line, or queue, of people © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line FIGURE 10 -4 A CRC card for the class Wait. Line © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line FIGURE 10 -5 A diagram of the classes Wait. Line and Customer © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line FIGURE 10 -5 A diagram of the classes Wait. Line and Customer © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line Algorithm for simulate © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line FIGURE 10 -6 A simulated waiting line © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line FIGURE 10 -6 A simulated waiting line © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line LISTING 10 -2 The class Wait. Line © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line LISTING 10 -2 The class Wait. Line © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line LISTING 10 -2 The class Wait. Line © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line LISTING 10 -2 The class Wait. Line © 2016 Pearson Education, Ltd. All rights reserved.
Simulating a Waiting Line LISTING 10 -2 The class Wait. Line © 2016 Pearson Education, Ltd. All rights reserved.
Computing the Capital Gain in a Sale of Stock FIGURE 10 -7 A CRC card for the class Stock. Ledger © 2016 Pearson Education, Ltd. All rights reserved.
Computing the Capital Gain in a Sale of Stock FIGURE 10 -8 A diagram of the classes Stock. Ledger and Stock. Purchase © 2016 Pearson Education, Ltd. All rights reserved.
Computing the Capital Gain in a Sale of Stock LISTING 10 -3 The class Stock. Ledger © 2016 Pearson Education, Ltd. All rights reserved.
Computing the Capital Gain in a Sale of Stock LISTING 10 -3 The class Stock. Ledger © 2016 Pearson Education, Ltd. All rights reserved.
Computing the Capital Gain in a Sale of Stock LISTING 10 -3 The class Stock. Ledger © 2016 Pearson Education, Ltd. All rights reserved.
Computing the Capital Gain in a Sale of Stock FIGURE 10 -9 A queue of (a) individual shares of stock; (b) grouped shares © 2016 Pearson Education, Ltd. All rights reserved.
Java Class Library: The Interface Queue Methods provided • • add offer remove poll element peek is. Empty size © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Deque • A double ended queue • Deque pronounced “deck” • Has both queuelike operations and stacklike operations © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Deque FIGURE 10 -10 An instance d of a deque © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Deque LISTING 10 -4 An interface for the ADT deque © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Deque LISTING 10 -4 An interface for the ADT deque © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Deque FIGURE 10 -11 A comparison of operations for a stack s, a queue q, and a deque d: (a) add; (b) remove; (c) retrieve © 2016 Pearson Education, Ltd. All rights reserved.
The ADT Deque Pseudocode that uses a deque to read and display a line of keyboard input © 2016 Pearson Education, Ltd. All rights reserved.
Computing the Capital Gain in a Sale of Stock Method buy creates an instance of Stock. Purchase and places it at the back of the deque © 2016 Pearson Education, Ltd. All rights reserved.
Computing the Capital Gain in a Sale of Stock The method sell is more involved © 2016 Pearson Education, Ltd. All rights reserved.
Computing the Capital Gain in a Sale of Stock The method sell is more involved © 2016 Pearson Education, Ltd. All rights reserved.
Java Class Library: The Interface Deque Methods provided • add. First, offer. First • • add. Last, offer. Last remove. First, poll. First remove. Last, poll. Last get. First, peek. First get. Last, peek. Last is. Empty, clear, size push, pop © 2016 Pearson Education, Ltd. All rights reserved.
Java Class Library: The Class Array. Deque • Implements the interface Deque • Constructors provided § Array. Deque() § Array. Deque(int initial. Capacity) © 2016 Pearson Education, Ltd. All rights reserved.
ADT Priority Queue • Consider how a hospital assigns a priority to each patient that overrides time at which patient arrived. • ADT priority queue organizes objects according to their priorities • Definition of “priority” depends on nature of the items in the queue © 2016 Pearson Education, Ltd. All rights reserved.
ADT Priority Queue LISTING 10 -5 An interface for the ADT priority queue © 2016 Pearson Education, Ltd. All rights reserved.
ADT Priority Queue LISTING 10 -5 An interface for the ADT priority queue © 2016 Pearson Education, Ltd. All rights reserved.
Tracking Your Assignments FIGURE 10 -12 A diagram of the class Assignment © 2016 Pearson Education, Ltd. All rights reserved.
Tracking Your Assignments FIGURE 10 -13 A diagram of the class Assignment. Log © 2016 Pearson Education, Ltd. All rights reserved.
Tracking Your Assignments LISTING 10 -6 The class Assignment. Log © 2016 Pearson Education, Ltd. All rights reserved.
Tracking Your Assignments LISTING 10 -6 The class Assignment. Log © 2016 Pearson Education, Ltd. All rights reserved.
Java Class Library: The Class Priority. Queue Basic constructors and methods • • Priority. Queue add offer remove poll element peek is. Empty, clear, size © 2016 Pearson Education, Ltd. All rights reserved.
End Chapter 10 © 2016 Pearson Education, Ltd. All rights reserved.
- 3 min quiz
- Adaptable priority queue
- Applications of priority queues
- Burman's priority list gives priority to
- Priority mail vs priority mail express
- Jenis struktur data
- Python queue clear
- Java stacks and queues
- Java stack exercises
- Java stacks and queues
- Representation of queues
- Message queues in unix
- Pipes in rtos
- Definition of queu
- Erisone queues
- Priority queue abstract data type
- Use case priority matrix for system
- Use case priority matrix for system
- Use case priority matrix for system
- Use case narrative example
- Deque and priority queue
- Use case ranking and priority matrix
- Use case ranking and priority matrix
- Yep 10
- Priority inheritance
- Stakeholder priority matrix
- Sendai framework guiding principles
- Verilog operator priority
- Hit another home run strategy
- Identify priority improvement areas
- Priorityprospect
- Min-priority queue
- Bottom up heap construction example
- Priority queue using heap
- Priority encoder
- Priority decoder
- Priority care 365
- Predictive prioritization
- Priority of sendai framework
- Order of priority of functional groups
- Ch3cccho
- Order of functional groups
- Order of priority of functional groups
- What are the six ministerial priorities
- Double ended queue
- 8051 interrupt
- Priority of sendai framework
- Daisy chain priority interrupt
- Symmetric min-max heap