Queues 1. Introduction A sequential collection of data Changes occur at both ends, not just one Queue applications –files waiting to be printed –"jobs"

Slides:



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

Queues A waiting line that grows by adding elements to its end and shrinks by taking elements from its front Line at the grocery store Cars in traffic.
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.
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
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.
 A queue is a waiting line…….  It’s in daily life:-  A line of persons waiting to check out at a supermarket.  A line of persons waiting.
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.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 18 Stacks.
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.
Data Structures and Algorithms Lecture (Queues) Instructor: Quratulain.
1 CSC 211 Data Structures Lecture 22 Dr. Iftikhar Azim Niaz 1.
CS 206 Introduction to Computer Science II 10 / 20 / 2008 Instructor: Michael Eckmann.
1 Queues CPS212 Gordon College. 2 Introduction to Queues A queue is a waiting line – seen in daily life –Real world examples – toll booths, bank, food.
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.
1 Queues and Priority Queues Chapter 8. 2 Introduction to Queues A queue is a waiting line – seen in daily life –Real world examples – toll booths, bank,
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.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Circular queue. Array-based Queue Use an array of size N in a circular fashion Three variables keep track of the front, rear, and size f index of the.
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.
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.”
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Chapter 16 Stack and Queues part2
Stacks & Recursion. Stack pushpop LIFO list - only top element is visible top.
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part R1. Elementary Data Structures.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
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.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Stacks And Queues Chapter 18.
Review of Stacks and Queues Dr. Yingwu Zhu. How does a Stack Work? Last-in-First-out (LIFO) data structure Adding an item Push operation Removing an item.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 18: Stacks and Queues.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
UNIT II Queue. Syllabus Contents Concept of queue as ADT Implementation using linked and sequential organization. – linear – circular queue Concept –
Queues Chapter 5 Queue Definition A queue is an ordered collection of data items such that: –Items can be removed only at one end (the front of the queue)
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Exam1 Review Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
1 Joe Meehean. 2  empty is the queue empty  size  enqueue (add) add item to end of queue  dequeue (remove) remove and return item at front of queue.
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 Another Linear ADT Copyright © 2009 Curt Hill.
1 Data Structures and Algorithms Queue. 2 The Queue ADT Introduction to the Queue data structure Designing a Queue class using dynamic arrays Linked Queues.
Review Array Array Elements Accessing array elements
Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009
18 Chapter Stacks and Queues
CS505 Data Structures and Algorithms
ADT description Implementations
Queues.
Stacks and Queues.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Lists.
Queues A queue is a data structure that is similar in spirit to a fair line. As you can see in this photo, the first dog in line can expect to be the first.
CMSC 341 Lecture 5 Stacks, Queues
Queues.
Lists.
Circular queue.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
CSC 143 Queues [Chapter 7].
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
[Most of the details about queues are left for to read about and work out in Lab 6.] Def. As a data structure, a queue is an ordered collection of data.
Getting queues right … finally (?)
Data Structures & Programming
Presentation transcript:

Queues 1

Introduction A sequential collection of data Changes occur at both ends, not just one Queue applications –files waiting to be printed –"jobs" waiting for the CPU or an I/O device –tokens waiting to be processed –signals on a channel (wired or wireless) Simulations 2

3 Structural Concept A sequence of data items –Items may be ANY type integers chars arrays structs Operations –Items can be removed only at the front –Items can be added only at the end –Only the front item may be viewed

Queue enqueue dequeue FIFO list - only front element is visible front index 4

5 The Queue ADT Operations –Construct a queue –Test for queue is empty/full –Enqueue (add new item at end) –Front (retrieve value of item at front) does not remove item –Dequeue (remove item from front) next item moves to the front

6 Static-Array Implementation Operations & constants –Q_MAX specifies item total –enqueue increments index use mod operator to "circle back to start" 1 st checks for full queue –dequeue increments index uses mod operator to "circle back to start" 1 st checks for empty queue

Static-array Implementation Example myFront myArray typedef Complx QueueElement; const int CAPACITY = 8; int myFront, myBack; QueueElement myQueue[CAPACITY]; Complx X; enqueue(&myArray,X); initially empty (myFront, myBack are negative) myBack 7

Caveats could be too small could be too large (wastes space) must be careful managing index solution (TBD) is dynamic storage going past the "end" 8

Solutions careful mgmt of index values (front, back) bigger queue circular queue dynamic array (TBD) 9

10 Circular Queue Each array element (a node) is 2 items –index of next node –data Last node has index of first node Or keep separate int index –subscript of "last" node –1 st node = MOD(lastnode+1,CAPACITY)

Some More Uses of a Queue job scheduling graphic display sequencing disk I/O access message processing spaceship launch sequence data "buffering" 11

Buffering data produced faster than can be used need to store it storage is called a "buffer" any stack or queue can be called a buffer 12