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.
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.
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.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Queue Overview Queue ADT Basic operations of queue
CS Data Structures II Review COSC 2006 April 14, 2017
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.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
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.
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.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 4 Prepared by İnanç TAHRALI.
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.
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.
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.
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,
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 18: Stacks and Queues.
Queues By Jimmy M. Lu. Overview Definition Standard Java Queue Operations Implementation Queue at Work References.
Review Array Array Elements Accessing array elements
Chapter 7 Queues.
Lecture No.09 Data Structures Dr. Sohail Aslam
CS505 Data Structures and Algorithms
Chapter 18: Stacks and Queues.
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.
Stacks and Queues.
Queues Queues Queues.
Stack and Queue APURBO DATTA.
CMSC 341 Lecture 5 Stacks, Queues
Queues.
Stacks Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Stacks, Queues, and Deques
Chapter 19: Stacks and Queues.
Queues.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
Memory Organization Process 1 (browser) Code Process 3 (word)
Stacks, Queues, and Deques
COMPUTER 2430 Object Oriented Programming and Data Structures I
18.5 Linked Queues Like a stack, a queue can be implemented using pointers and nodes Allows dynamic sizing, avoids issue of wrapping indices NULL front.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
Queues Jyh-Shing Roger Jang (張智星)
Visit for more Learning Resources
Queues Definition of a Queue Examples of Queues
Stacks, Queues, and Deques
CSCS-200 Data Structure and Algorithms
Queues Chapter 8 © 2011 Pearson Addison-Wesley. All rights reserved.
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

Queue.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 ASK: Advantages & disadvantages of using ints as return values

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