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

Slides:



Advertisements
Similar presentations
Queues Printer queues Several jobs submitted to printer Jobs form a queue Jobs processed in same order as they were received.
Advertisements

Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
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.
1 Data Structures CSCI 132, Spring 2014 Lecture 8 Implementing Queues.
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.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
LINKED QUEUES P LINKED QUEUE OBJECT Introduction Introduction again, the problem with the previous example of queues is that we are working.
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.
Data Structure Dr. Mohamed Khafagy.
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.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Tirgul 3 Subjects of this Tirgul: Linked Lists Doubly-Linked Lists Sparse Matrices Stack Queue.
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.
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.
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
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
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.
Queues Chapter 3. Objectives Introduce the queue abstract data type. – Queue methods – FIFO structures Discuss inheritance in object oriented programming.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Data Structures Using C++ 2E Chapter 8 Queues. Data Structures Using C++ 2E2 Objectives Learn about queues Examine various queue operations Learn how.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
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.
Stacks And Queues Chapter 18.
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)
CHP-4 QUEUE. 1.INTRODUCTION  A queue is a linear list in which elements can be added at one end and elements can be removed only at other end.  That.
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.
M180: Data Structures & Algorithms in Java Queues 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,
Queue Section 3 6/12/ The Abstract Data Type Queue A queue is a list from which items are deleted from one end (front) and into which items are.
1 Data Structures CSCI 132, Spring 2016 Notes_ 5 Stacks.
Review Array Array Elements Accessing array elements
Data Structures Using C++ 2E
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.
Stacks and Queues.
Stack and Queue APURBO DATTA.
CMSC 341 Lecture 5 Stacks, Queues
Stacks, Queues, and Deques
Stacks, Queues, and Deques
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Queues Definition of a Queue Examples of Queues
Stacks, Queues, and Deques
CSCS-200 Data Structure and Algorithms
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 error value is returned  ErrorCode Enqueue(int newItem);

Stack.Dequeue  If the queue is not empty, then the front item is removed & returned via the out parameter.  If the queue is empty, then an underflow error has occurred, and an error value is returned.  ErrorCode Dequeue(out int FrontVal);

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 underflow error value is returned.  ErrorCode Peek(out int FrontVal);

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

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

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  ErrorCode Enqueue(int newItem) { if(counter>=items.Length) return ErrorCode.Overflow; counter++; back = ((back+1)== items.Length) ? 0 : (back+1); items[back] = newItem; return ErrorCode.NoError; }

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