Académique Documents
Professionnel Documents
Culture Documents
Chapter 6
Chapter Objectives
Chapter 6: Queues
Queue Abstract Data Type
Chapter 6: Queues
Queue Abstract Data Type (continued)
Chapter 6: Queues
A Print Queue
Chapter 6: Queues
A Print Queue (continued)
Chapter 6: Queues
The Unsuitability of a Print Stack
Chapter 6: Queues
Using a Queue for Traversing a Multi-
Branch Data Structure
• A graph models a network of nodes, with many links
connecting each node to other nodes in the network
• A node in a graph may have several successors
• Programmers often use a queue to ensure that nodes
closer to the starting point are visited before nodes that
are farther away
Chapter 6: Queues
Specification for a Queue Interface
Chapter 6: Queues
Maintaining a Queue of Customers
Chapter 6: Queues
Maintaining a Queue of Customers
(continued)
Chapter 6: Queues
Maintaining a Queue of Customers
(continued)
Chapter 6: Queues
Using a Single-Linked List to Implement a
Queue
• Can implement a queue using a single-linked list
• Insertions are at the rear of a queue and removals are
from the front
• Need a reference to the last list node
• Number of elements in the queue is changed by
methods insert and remove
Chapter 6: Queues
Using a Single-Linked List to Implement a
Queue (continued)
Chapter 6: Queues
Implementing a Queue Using Java’s
LinkedList
• Can be implemented as an adapter of any class that
implements the List interface
• ArrayList
• Vector
• LinkedList
• Removal is O(n) with a linked list
• O(n) when using ArrayList or Vector
Chapter 6: Queues
Implementing a Queue Using a Circular
Array
• Time efficiency of using a single- or double-linked list to
implement a queue is acceptable
• However there are some space inefficiencies
• Storage space is increased when using a linked list due
to references stored at each list node
• Array Implementation
• Insertion at rear of array is constant time
• Removal from the front is linear time
• Removal from rear of array is constant time
• Insertion at the front is linear time
Chapter 6: Queues
Implementing a Queue Using a Circular
Array (continued)
Chapter 6: Queues
Implementing a Queue Using a Circular
Array (continued)
Chapter 6: Queues
Implementing a Queue Using a Circular
Array (continued)
Chapter 6: Queues
Implementing a Queue Using a Circular
Array (continued)
Chapter 6: Queues
Comparing the Three Implementations
Chapter 6: Queues
Simulating Waiting Lines Using Queues
(continued)
• System designers often use computer models to
simulate physical systems
• Airline check-in counter for example
• A special branch of mathematics called queuing
theory has been developed to study such problems
Chapter 6: Queues
Simulate a Strategy for Serving Airline
Passengers
Chapter 6: Queues
Simulate a Strategy for Serving Airline
Passengers (continued)
Chapter 6: Queues
Simulate a Strategy for Serving Airline
Passengers (continued)
Chapter 6: Queues
Simulating Waiting Lines Using Queues
(continued)
Chapter 6: Queues
Simulating Waiting Lines Using Queues
(continued)
Chapter 6: Queues
Simulating Waiting Lines Using Queues
(continued)
Chapter 6: Queues
Simulating Waiting Lines Using Queues
(continued)
Chapter 6: Queues
Chapter Review
Chapter 6: Queues