Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.

Slides:



Advertisements
Similar presentations
1 Array-based Implementation An array Q of maximum size N Need to keep track the front and rear of the queue: f: index of the front object r: index immediately.
Advertisements

Stacks, Queues, and Deques. 2 A stack is a last in, first out (LIFO) data structure Items are removed from a stack in the reverse order from the way they.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
CS Data Structures II Review COSC 2006 April 14, 2017
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.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
Cmpt-225 Queues. A queue is a data structure that only allows items to be inserted at the end and removed from the front Queues are FIFO (First In First.
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, Deques and Priority Queues Chapter 10 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
1 Lecture 26 Abstract Data Types – IV Overview  The List ADT  Implementing Stacks as Linked List  Linked List Implementation of Queues .  Preview:
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
COP INTERMEDIATE JAVA Data Structures. A data structure is a way of organizing a collection of data so that it can be manipulated effectively. A.
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)
1 Lecture 14: Queues Lecturer: Santokh Singh CompSci 105 SS 2005 Principles of Computer Science.
LECTURE 27: DEQUES CSC 212 – Data Structures. Roses are red and violets are blue Implement push, pop, & top And you’re a Stack too! Stack & ADT Memory.
UNIVERSAL COLLEGE OF ENGG. AND TECH. 3 RD IT. QUEUE ( data structure)
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.
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
Lecture 10 b Stacks b Queues. 2 Stacks b A stack ADT is linear b Items are added and removed from only one end of a stack b It is therefore LIFO: Last-In,
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,
Week 15 – Monday.  What did we talk about last time?  Tries.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
© 2004 Goodrich, Tamassia Queues. © 2004 Goodrich, Tamassia Stacks2 The Queue ADT The Queue ADT stores arbitrary objects Insertions and deletions follow.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Chapter 7 Stacks © 2006 Pearson Addison-Wesley. All rights reserved 7A-1.
Queues Chapter 8 (continued)
Chapter 7 Queues.
Data Abstraction & Problem Solving with C++
18 Chapter Stacks and Queues
Week 4 - Monday CS221.
Queues 5/11/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
12 Collections Software Solutions Lewis & Loftus java 5TH EDITION
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Double-Ended Queues Chapter 5.
Marcus Biel, Software Craftsman
CC 215 Data Structures Queue ADT
Chapter 15 Lists Objectives
Csc 2720 Data structure Instructor: Zhuojun Duan
CENG 213 Data Structure Queue 7/2/2018.
Chapter 12: Data Structures
Stacks and Queues.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Priority Queue.
Queues, Deques and Priority Queues
Queues.
Queues, Deques and Priority Queues
Queue and Priority Queue Implementations
Chapter 14: Queue and Priority Queue Implementations
Queues A first-in, first-out or FIFO data structure.
Figure 7.1 Some queue operations. Figure 7.1 Some queue operations.
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
Copyright © Aiman Hanna All rights reserved
Linked Lists Chapter 5 (continued)
CS210- Lecture 6 Jun 13, 2005 Announcements
Stacks, Queues, and Deques
Chapter 7 (continued) © 2011 Pearson Addison-Wesley. All rights reserved.
Queues Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Chapter 7 © 2011 Pearson Addison-Wesley. All rights reserved.
Queues.
Stack Implementations
Queues, Deques, and Priority Queues
Queue, Deque, and Priority Queue Implementations
Presentation transcript:

Queues cont. Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved

RECAP : An Array-Based Implementation of Queue Limitation => Rightward shift © 2011 Pearson Addison-Wesley. All rights reserved

RECAP : A circular Array-Based Implementation A circular array eliminates the problem of rightward drift Keep track of the: - front - back - counter Figure 8-9 A circular implementation of a queue See Notes © 2011 Pearson Addison-Wesley. All rights reserved

RECAP : An Implementation That Uses the ADT List If the item at the end of the list represents the back of the queue, the following implementations can be used enqueue(newItem) list.add(list.size(), newItem) Figure 8-13 An implementation that uses the ADT list See Notes © 2011 Pearson Addison-Wesley. All rights reserved

The Java Collections Framework Interface Queue JCF has a queue interface called Queue Derived from interface Collection Adds methods: element: retrieves, but does not remove head offer: inserts element into queue peek: retrieves, but does not remove head poll: retrieves and removes head remove: retrieves and removes head © 2011 Pearson Addison-Wesley. All rights reserved

The Java Collections Framework Interface Deque Deque = double-ended queue (pronounced “deck”) Allows us to insert and delete from either end Useful methods: addFirst, addLast, peekFirst, peekLast, getFirst, getLast, removeFirst, removeLast Thus, may function as both a stack and a queue © 2011 Pearson Addison-Wesley. All rights reserved

Comparing Implementations All of the implementations of the ADT queue mentioned are ultimately either Array based Reference based Fixed size versus dynamic size A statically allocated array Prevents the enqueue operation from adding an item to the queue if the array is full A resizable array or a reference-based implementation Does not impose this restriction on the enqueue operation © 2011 Pearson Addison-Wesley. All rights reserved

A Summary of Position-Oriented ADTs List Stack Queue Stacks and queues Only the end positions can be accessed Lists All positions can be accessed © 2011 Pearson Addison-Wesley. All rights reserved

A Summary of Position-Oriented ADTs Stacks and queues are very similar Operations of stacks and queues can be paired off as createStack and createQueue Stack isEmpty and queue isEmpty push and enqueue pop and dequeue Stack peek and queue peek © 2011 Pearson Addison-Wesley. All rights reserved

A Summary of Position-Oriented ADTs ADT list operations generalize stack and queue operations length add remove get © 2011 Pearson Addison-Wesley. All rights reserved

Comparing Implementations Reference-based implementations A linked list implementation More efficient (does not require a shift) The ADT list implementation Simpler to write © 2011 Pearson Addison-Wesley. All rights reserved

Summary The definition of the queue operations gives the ADT queue first-in, first-out (FIFO) behavior A reference-based implementation of a queue uses either A circular linked list A linear linked list with a head reference and a tail reference An array-based implementation of a queue is prone to rightward drift A circular array eliminates the problem of rightward drift © 2011 Pearson Addison-Wesley. All rights reserved

Summary To distinguish between the queue-full and queue-empty conditions in a queue implementation that uses a circular array, you can Count the number of items in the queue Leave one array location empty © 2011 Pearson Addison-Wesley. All rights reserved