Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.

Slides:



Advertisements
Similar presentations
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
Advertisements

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.
COSC 1P03 Data Structures and Abstraction 9.1 The Queue Whenever you are asked if you can do a job, tell 'em, "Certainly, I can!" Then get busy and find.
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.
Data Structure (Part I) Stacks and Queues. Introduction to Stack An stack is a ordered list in which insertion and deletions are made at one end. –The.
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.
A queue is an ADT which allows data values to be accessed only one at a time and only the first inserted. The rule imposed on a queue is: First In First.
Queues CS-212 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed in their.
CHAPTER 7 Queues.
Queues 4/14/2017 5:24 PM 5.2 Queues Queues Dr Zeinab Eid.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 18: Stacks And Queues.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Queue Overview Queue ADT Basic operations of queue
Data Structures Chapter 3 Queues Andreas Savva. 2 Queues A data structure modeled after a line of people waiting to be served. A data structure modeled.
CS Data Structures II Review COSC 2006 April 14, 2017
Queues. What is a queue? First-in first-out data structure (FIFO) New objects are placed at rear Removal restricted to front Examples?
Tirgul 3 Subjects of this Tirgul: Linked Lists Doubly-Linked Lists Sparse Matrices Stack Queue.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
Main Index Contents 11 Main Index Contents Model for a Queue Model for a Queue The Queue The Queue ADTQueue ADT (3 slides) Queue ADT Radix Sort Radix Sort.
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.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed.
Queues CS-240 & CS-341 Dick Steflik. Queues First In, First Out operation – FIFO As items are added they are chronologically ordered, items are removed.
Stacks, Queues, and Deques
© 2004 Goodrich, Tamassia Queues1. © 2004 Goodrich, Tamassia Queues2 The Queue ADT (§4.3) The Queue ADT stores arbitrary objects Insertions and deletions.
Stacks, Queues, and Deques. 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.
1 Queues (Walls & Mirrors - Chapter 7). 2 Overview The ADT Queue Linked-List Implementation of a Queue Array Implementation of a Queue.
Stacks, Queues, and Deques
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
CS 1031 Queues Definition of a Queue Examples of Queues Design of a Queue Class Different Implementations of the Queue Class.
TK1924 Program Design & Problem Solving Session 2011/2012 L6: Queues.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues.
Chapter 16 Stacks & Queues. Objective In this chapter we will learn:  Stacks  Queues  Different implementations (arrays and linked list) of both 
1 Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
Data Structures Using Java1 Chapter 7 Queues. Data Structures Using Java2 Chapter Objectives Learn about queues Examine various queue operations Learn.
Stacks The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Stacks and Queues Based on D.S. Malik, Java Programming: Program Design Including Data Structures.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Scis.regis.edu ● CS-362: Data Structures Week 8 Dr. Jesús Borrego 1.
Queue 09/10/081. Queue (Linear Queue) It is a linear data structure consisting of list of items. In queue, data elements are added at one end, called.
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.
Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues.
Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Chapter 7 Queues Introduction Queue applications Implementations.
M180: Data Structures & Algorithms in Java Queues Arab Open University 1.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
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,
Review Array Array Elements Accessing array elements
CS505 Data Structures and Algorithms
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Stacks The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
CENG 213 Data Structure Queue 7/2/2018.
Queue data structure.
Queue.
Stack and Queue APURBO DATTA.
CMSC 341 Lecture 5 Stacks, Queues
Stacks, Queues, and Deques
Stacks, Queues, and Deques
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
Queues Jyh-Shing Roger Jang (張智星)
Queues Definition of a Queue Examples of Queues
Stacks, Queues, and Deques
Queues Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Data Structures & Programming
Presentation transcript:

Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz

Overview  Queue Introduction  Queue Specification  Implementation Of Queues

Queue Introduction  A queue is an abstract data type in which all the insertions are made at one end of the queue (the back, or rear), while all deletions are made at the opposite end (the front). The first entry that was added is the first entry that will be removed  Sometimes referred to as First-In First Out (FIFO)

Queue Class Specification (API)  The API used here is loosely based on the.Net FCL Stack class.

Queue.Enqueue  If the queue is not full, add item to the back/rear of the queue.  If the queue is full, an overflow error has occurred, and an OverflowException is thrown  void Enqueue(int newItem);  // throw OverflowException

Stack.Dequeue  If the queue is not empty, then the front item is removed & return it.  If the queue is empty, then an underflow error has occurred, and an UnderflowException is thrown  int Dequeue(); // throws UnderflowException

Queue.Peek  If the queue is not empty, then the front item is returned via the out parameter. The queue itself is unchanged  If the queue is empty, then an UnderflowException is thrown  int Peek(); // throws UnderflowException

Queue.IsEmpty  If the queue is empty, then true is returned. Otherwise, returns false.  bool isEmpty();

Queue: Implementation  Each instance of the class will use per-instance variables to keep track of An array of integers  These represent the contents of the queue An integer to keep track of the index of the ‘front’ of the queue An integer to keep track of the index of the ‘back’ of the queue The count of items that are in the Queue

Queue: Implementation: Ctor  public class Queue { int []items; int iFront; int iBack; int count; public Queue() { items = new int[10]; iFront = 0; iBack = 0; count = 0; }  Note: We should also provide at least one other constructor, so that a person could choose a different size for the queue.

pr

Solution  Shift items down when space towards the front is free Results in lots of work  Implement a more efficient queue A circular queue, or circular list

Queue: Implementation: Ctor  public class Queue { int []items; int iFront; int iBack; int counter; public Queue() { [] items = new int[10]; iFront = 0; iBack = 0; counter = 0; }  Note: We should also provide at least one other constructor, so that a person could choose a different size for the queue.

Implementing Circular Queues: Counter Method  int Enqueue(int newItem) { if(counter>=items.Length) throw new OverflowException("No space in Q"); counter++; back = ((back+1)== items.Length) ? 0 : (back+1); items[back] = newItem; }

Summary  Simple to use, pretty simple to implement Some more bookkeeping is required  Used in cases wherein items need to be serviced in the order in which they arrive GUI event systems DB transactions