Queues, Deques, and Priority Queues Chapter 23 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All.

Slides:



Advertisements
Similar presentations
Lists Chapter 4 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X.
Advertisements

Stacks Chapter 21 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Fundamentals of Python: From First Programs Through Data Structures
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 4.
CS Data Structures II Review COSC 2006 April 14, 2017
A List Implementation That Links Data Chapter 6 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Queues and Priority Queues
Chapter 13 Queues and Priority Queues CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Completing the Linked Implementation of a List Chapter 7 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
List Implementations That Use Arrays Chapter 5 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Queues, Deques, and Priority Queues Chapter Chapter Contents Specifications for the ADT Queue Using a Queue to Simulate a Waiting Line The Classes.
Iterators Chapter 8 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Queue, Deque, and Priority Queue Implementations Chapter 24 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Queues, Deques, and Priority Queues Chapter Chapter Contents Specifications for the ADT Queue Using a Queue to Simulate a Waiting Line The Classes.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Stack Implementations Chapter 22 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Chapter 7 Queues. © 2005 Pearson Addison-Wesley. All rights reserved7-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
Queues. From last time: Java's built-in java.util.Stack class Consider the javadoc for Java’s built-in java.util.Stack class (
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Queue, Deque, and Priority Queue Implementations.
Queues, Deques and Priority Queues Chapter 10 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Queues, Deques, and Priority Queues Chapter 23 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Queues, Deques, and Priority Queues Chapter Chapter Contents Specifications for the ADT Queue Using a Queue to Simulate a Waiting Line The Classes.
A Binary Search Tree Implementation Chapter 27 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Dictionaries Chapter 17 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
Chapter 6.6, (event-driven simulation) Queues 1CSCI 3333 Data Structures.
Queues and Priority Queues
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
© 2006 Pearson Education Chapter 12: Data Structures Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis,
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
Queue What is a queue?. Queues A queue is similar to waiting in line for a service, e.g., at the bank, at the bathroom –The first item put on the queue.
Lists Chapter 4 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
The Abstract Data Type Queue A queue New items enter at the back, or rear, of the queue Items leave from the front of the queue First-in, first-out (FIFO)
Chapter 8 Queues. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
© 2011 Pearson Addison-Wesley. All rights reserved 8 B-1 Chapter 8 (continued) Queues.
Stacks Chapter 5 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Chapter 7 A Queues. © 2004 Pearson Addison-Wesley. All rights reserved7 A-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear,
Click to edit Master text styles Stacks Data Structure.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
Chapter 7 Stacks © 2006 Pearson Addison-Wesley. All rights reserved 7A-1.
Queues Chapter 8 (continued)
Data Abstraction & Problem Solving with C++
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Chapter 13 Queues and Priority Queues
Queues, Deques and Priority Queues
Queue, Deque, and Priority Queue Implementations
Queue, Deque, and Priority Queue Implementations
Queues, Deques and Priority Queues
Stacks Chapter 5 Adapted from Pearson Education, Inc.
A List Implementation That Links Data
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Stack Implementations
Queues CSC212.
A Heap Implementation Chapter 26 Adapted from Pearson Education, Inc.
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
A List Implementation That Links Data
Queues.
Stack Implementations
© 2016 Pearson Education, Ltd. All rights reserved.
A List Implementation that Links Data
© 2016 Pearson Education, Ltd. All rights reserved.
Queues, Deques, and Priority Queues
Queue, Deque, and Priority Queue Implementations
Presentation transcript:

Queues, Deques, and Priority Queues Chapter 23 Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X

Chapter Contents Specifications for the ADT Queue Using a Queue to Simulate a Waiting Line – The Classes WaitLine and Customer Using a Queue to Compute the capital Gain in a Sale of Stock – The Classes StockLedger and StockPurchase Java Class Library: the Interface Queue Specifications of the ADT Deque

Chapter Contents Using a Deque to Compute the Capital Gain in a Sale of Stock Specifications of the ADT Priority Queue Using a Priority Queue to Compute the Capital Gain in a Sale of Stock Specifications of the ADT Priority Queue Using a Priority Queue to Track Your Assignments

Specifications for the ADT Queue Queue organizes entries according to order of entry – Exhibits first-in, first-out behavior – Contrast to stack which is last-in, first-out All additions are at the back of the queue Front of queue has items added first

Specifications for the ADT Queue Fig Some everyday queues.

Specifications for the ADT Queue View interface for a queue of objects View interface Note methods – enqueue – dequeue – getFront – isEmpty – clear

Specifications for the ADT Queue Fig Queue of strings after (a) enqueue adds Jim; (b) Jess; (c) Jill; (d) Jane;

Specifications for the ADT Queue Fig Queue of strings after (e) enqueue adds Joe; (f) dequeue retrieves, removes Jim; (g) enqueue adds Jerry; (h) dequeue retrieves, removes Jess.

Using a Queue to Simulate a Waiting Line Fig A line, or queue of people.

Classes WaitLine and Customer Fig A CRC card for the class WaitLine.

Classes WaitLine and Customer Fig A diagram of the classes WaitLine and Customer.

Classes WaitLine and Customer Fig A simulated waiting line … continued →

Classes WaitLine and Customer Fig (ctd) A simulated waiting line.

The Class Waitline View source codesource code Note methods – Constructor – simulate – displayResults – reset

Using a Queue to Compute Capital Gain in a Sale of Stock Must sell stocks in same order they were purchased – Must use the difference in selling price and purchase price to calculate capital gain We use a queue to – Record investment transactions chronologically – Compute capital gain of the stock

Classes StockLedger and StockPurchase Fig A CRC card for the class StockLedger

Classes StockLedger and StockPurchase Fig A diagram of the class StockLedger and StockPurchase.

Classes StockLedger and StockPurchase View source code for class StockLedgersource code Note method – Constructor – buy – sell

Classes StockLedger and StockPurchase Fig A queue of (a) individual shares of stock; (b) grouped shares.

Java Class Library: The Interface Queue Similar to our QueueInterface – Specifies more methods Methods provided

Specifications of the ADT Deque A Double ended queue Has operations that – Add, remove, or retrieve entries – At both its front and back Combines and expands the operations of queue and stack

Specifications of the ADT Deque Fig An instance of a deque.

Specifications of the ADT Deque A Java interface

Specifications of the ADT Deque Fig A comparison of the operations that add, remove, and retrieve the entries of a stack s, queue q, and a deque d ; (a) add;

Specifications of the ADT Deque Fig A comparison of the operations that add, remove, and retrieve the entries of a stack s, queue q, and a deque d ; (b) remove;

Specifications of the ADT Deque Fig A comparison of the operations that add, remove, and retrieve the entries of a stack s, queue q, and a deque d ; (c) retrieve.

Using a Deque to Compute Capital Gain in Sale of Stock Revise the class StockPurchase – Represents purchase of n shares at d dollars per share – Constructor is changed – Accessor methods for new fields added Revise class StockLedger – Method ledger now an instance of a deque – Method buy now creates instance of StockPurchase, places it at back of deque – Method sell also altered Click to view new methods

Specifications of the ADT Priority Queue Organizes objects according to priorities – Contrast to regular queue in order of arrival Priority queue example – a hospital ER Priority can be specified by an integer – Must define whether high number is high priority or … – Low number (say 0) is high priority Other objects can specify priority – Object must have a compareTo method

Specifications of the ADT Priority Queue Note specification for ADT priority queuespecification Methods specified – add – remove – peek – getSize – clear

Using Priority Queue to Track Your Assignments Organize class or work assignments by due dates – Early due date, higher priority Figure 23-2 diagram of class Assignment

Using Priority Queue to Track Your Assignments Fig A diagram of the class AssignmentLog Note source code of classsource code