A queue is a linear, homogeneous, container that stores and dispenses its content in a FIFO manner. FIFO - Fast In First Out The first (most distant) item.

Slides:



Advertisements
Similar presentations
STACKS & QUEUES. Stacks Abstract data types An abstract data type (ADT) is an abstraction of a data structure An ADT specifies : –Data stored –Operations.
Advertisements

Ceng-112 Data Structures I Chapter 5 Queues.
A queue is a linear, homogeneous, container that stores and dispenses its content in a FIFO manner. FIFO - First In First Out The first (most distant)
Queues1 Part-B2 Queues. Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions follow the first-in first-out scheme.
Queue ADT Operations Enqueue, Dequeue, Peek, isEmpty Implementation: Circular Array (Weiss), Linked List, Circular Array (text) Application: Level-Order.
Topic 9 The Queue ADT.
1 Queues – Chapter 3 A queue is a data structure in which all additions are made at one end called the rear of the queue and all deletions are made from.
CHAPTER 7 Queues.
1 Queues (5.2) CSE 2011 Winter May Announcements York Programming Contest Link also available from.
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 4.
Chapter 5 Queues Modified. Chapter Scope Queue processing Comparing queue implementations 5 - 2Java Software Structures, 4th Edition, Lewis/Chase.
Queues Chapter 6. Chapter Objectives  To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface for insertion.
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
Queues.
1 Lecture 24 Abstract Data Types (ADT) –I Overview  What is an Abstract Data type?  What is Stack ADT?  Stack ADT Specifications  Array Implementation.
Queues What is a queue? Queue Implementations: –As Array –As Circular Array –As Linked List Applications of Queues. Priority queues.
Queues Chapter 6. Chapter 6: Queues2 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in the Queue interface.
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 13: Queues and Vectors.
CS 106 Introduction to Computer Science I 12 / 13 / 2006 Instructor: Michael Eckmann.
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Queues CSI 1101 N. El Kadri. 2 Definitions A queue is a linear abstract data type such that insertions are made at one end, called the rear, and removals.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
Software reuse means to “borrow” existing code. How can you reuse an existing class to make a new one? Such reuse is really an adaptation -- using the.
Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.
09-1 Queues and List-Based ADT Implementations Problem Set: PS3 due Wednesday, March 7 Wellesley College CS230 Lecture 09 Monday, February 26 Handout #18.
Queues Chapter 6. Chapter 6: Queues Chapter Objectives To learn how to represent a waiting line (queue) and how to use the five methods in the Queue interface:
Lecture7: Queue Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Stacks and Queues. 2 3 Runtime Efficiency efficiency: measure of computing resources used by code. can be relative to speed (time), memory (space), etc.
Cousin of the Stack.  An abstract data type (container class) in which items are entered at one end and removed from the other end  First In First.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Queue. Avoid confusion Britain Italy 6 Applications of Queues Direct applications –Waiting lists, bureaucracy –Access to shared resources (e.g.,
M180: Data Structures & Algorithms in Java Queues Arab Open University 1.
A stack is a linear, homogeneous, container that stores and dispenses its content in a LIFO manner. LIFO - Last In First Out The last (most recent) item.
Queue. The Queue ADT Insertions and deletions follow the first-in first-out scheme Insertions are at the rear of the queue and removals are at the front.
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.
1 Queues Chapter 4. 2 Objectives You will be able to Describe a queue as an ADT. Build a dynamic array based implementation of a queue ADT.
Queues 1. Queue  a queue represents a sequence of elements where elements can be added at the back of the sequence and removed from the front of the.
Queues By Jimmy M. Lu. Overview Definition Standard Java Queue Operations Implementation Queue at Work References.
Queues1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition, by M. T. Goodrich,
Stacks and Queues. 2 Abstract Data Types (ADTs) abstract data type (ADT): A specification of a collection of data and the operations that can be performed.
Queues.
Stacks and Queues.
Stack A stack is a linear, homogeneous, container that stores and dispenses its content in a LIFO manner. LIFO - The last (most recent) item inserted,
Csc 2720 Data structure Instructor: Zhuojun Duan
Stack A stack is a linear, homogeneous, container that stores and dispenses its content in a LIFO manner. LIFO - The last (most recent) item inserted,
Stack A stack is a linear, homogeneous, container that stores and dispenses its content in a LIFO manner. LIFO - The last (most recent) item inserted,
CSE 373: Data Structures and Algorithms
Stacks and Queues.
Stacks and Queues.
Queues What is a queue? Queue Implementations: As Array
Queues 11/9/2018 6:28 PM Queues 11/9/2018 6:28 PM Queues.
Queues 11/16/2018 4:18 AM Queues 11/16/2018 4:18 AM Queues.
Queues 11/16/2018 4:19 AM Queues 11/16/2018 4:19 AM Queues.
Queue.
Stacks and Queues.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
CSC 143 Queues [Chapter 7].
Queues 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser,
Queues 12/30/2018 9:24 PM Queues 12/30/2018 9:24 PM Queues.
Stacks and Queues CLRS, Section 10.1.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Queues What is a Queue? Queue Implementations: As Array
Queues Jyh-Shing Roger Jang (張智星)
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
Stacks and Queues.
Queues What is a queue? Queue Implementations: As Array
Presentation transcript:

A queue is a linear, homogeneous, container that stores and dispenses its content in a FIFO manner. FIFO - Fast In First Out The first (most distant) item inserted, and not yet removed, will be the first (next) item dispensed. Real World Examples  assembly lines  waiting line The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.

enqueue insert a new item into the queue dequeue remove one item from the container front inspect one item from the container, but don’t remove it An Abstract Picture front dequeue enqueue The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.

Class Specification Domain sequence of Object Constructor public Queue() post: this == sequence{} Query methods public boolean isEmpty() post: result == ( this-> size() == 0) public Object front() pre: ! isEmpty() post: result == this-> first() Update methods public void enque(Object z) post: this == -> append( z ) public void dequeue() pre: ! isEmpty() (throws java.util.NoSuchElementException) post: this == -> subSequence( 2, -> size() ) Queue The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.

Queue + Queue() + boolean isEmpty() + void enqueue(Object z) + void dequeue() + Object front() Example Queue q1, q2; String str; q1 = new Queue(); q1.enqueue( “droopy” ); q1.enqueue( “rupie” ); q1.enqueue( “snoopy” ); q1.dequeue(); q1.enqueue( “soupy” ); str = (String) q1.front(); q1.enqueue( “loopy” ); q1.enqueue( “goopy” ); q1.dequeue(); q1.enqueue( q1.front() ); q2 = new Queue(); while ( !q1.isEmpty() ) { q2.enqueue( q1.front() ); q1.dequeue(); } The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.

In the computing environment...  is queued.  Graphical User Interfaces (GUIs) depend upon event queues.  Documents sent to the printer are spooled (queued).  Data transferred to a stream are buffered (queued).  Machine instructions are executed using a sophisticated queue, known as a pipeline. The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.

Suppose you inherit LinkedList. Which end of the list is the front of the queue? How does the code for enqueue differ from dequeue? How many iterators? Double or single linking? Suppose you use an array to store the queue content. What happens when the number of enqueues exceeds the array length? The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.

Bounded List Representation This is best accomplished by treating an array like it is a circular structure, also called a ring buffer. [0] [1] [2] [3] [size] 1 3 newest oldest oldest is the index of the queue’s front newest is the index of the queue’s rear Note: This representation requires n+1 cells for a queue of length n. The Object of Data Abstraction and Structure, David D. Riley © Addison Wesley pub.