Queues.

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.
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.
 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.
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.
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.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
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.
Chapter 16 Stack and Queues part2
Adapted from instructor resources Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights.
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.
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.
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)
Exam1 Review Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
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. Introduction A sequential collection of data Changes occur at both ends, not just one Queue applications –files waiting to be printed –"jobs"
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 18: Stacks and Queues.
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.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 2b. Simple Containers: The Queue.
Review Array Array Elements Accessing array elements
CSCE 210 Data Structures and Algorithms
Data Structures Using C, 2e
Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009
Queues.
18 Chapter Stacks and Queues
CS505 Data Structures and Algorithms
Chapter 18: Stacks and Queues.
ADT description Implementations
Queues.
CSE 373: Data Structures and Algorithms
Lectures Queues Chapter 8 of textbook 1. Concepts of queue
Stacks and Queues.
Queues Queues Queues.
Stack and Queue APURBO DATTA.
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 11/9/2018 6:28 PM Queues 11/9/2018 6:28 PM Queues.
Lists.
Chapter 19: Stacks and Queues.
Queues 11/16/2018 4:19 AM Queues 11/16/2018 4:19 AM Queues.
Circular queue.
Queues.
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
Stacks & Recursion.
CSC 143 Queues [Chapter 7].
Queues 12/3/2018 Queues © 2014 Goodrich, Tamassia, Goldwasser Queues.
Queues 12/30/2018 9:24 PM Queues 12/30/2018 9:24 PM Queues.
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Priority Queues & Heaps
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
Stacks, Queues, and Deques
[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

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

Structural Concept A sequence of data items Operations 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

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

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

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

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

Caveats could be too small could be too large (wastes space) must be careful managing index going past the "end" solution (TBD) is dynamic storage Lab2: build a queue. enqueue, front-output in seq'l order, dequeue

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

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 1st 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"

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