Queue ADT (Abstract Data Type) N … 3 2 1.

Slides:



Advertisements
Similar presentations
Stack & Queues COP 3502.
Advertisements

Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
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.
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.
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.
Chapter 5 Queues Modified. Chapter Scope Queue processing Comparing queue implementations 5 - 2Java Software Structures, 4th Edition, Lewis/Chase.
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
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.
Trees & Graphs Nell Dale & John Lewis (adaptation by Michael Goldwasser and Erin Chambers)
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 18 Stacks and Queues.
September 05 Kraemer UGA/CSCI 2720 Lists – Part I CSCI 2720 Eileen Kraemer The University of Georgia.
CMSC 202 Stacks and Queues. What’s a Queue? A queue is a linear collection of homogeneous data in which items added to the queue must be placed at the.
Stacks And Queues Chapter 18.
Arrays and Collections Tonga Institute of Higher Education.
Computer Science Department Data Structures and Algorithms Queues Lecture 5.
Chapter 3 The easy stuff. Lists If you only need to store a few things, the simplest and easiest approach might be to put them in a list Only if you need.
Stacks and Queues CMSC 201. Stacks and Queues Sometimes, when we use a data-structure in a very specific way, we have a special name for it. This is to.
1 Data Organization Example 1: Heap storage management Maintain a sequence of free chunks of memory Find an appropriate chunk when allocation is requested.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 18: Stacks and Queues.
Queues and Priority Queue Implementations Chapter 14 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
UNIT-V ABSTRACT DATA TYPE 1.LIST 2.STACK 3.QUEUE EC6301-II-ECE-C.
1 Data Organization Example 1: A simple text editor –Store the text buffer as a list of lines. –How would we implement the UNDO operation? Example 2: Parsing.
Stack ADT (Abstract Data Type) N …
Elementary Data Structures
Review Array Array Elements Accessing array elements
Cpt S 122 – Data Structures Abstract Data Types
Data Structures Using C++ 2E
18 Chapter Stacks and Queues
G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Chapter 4 The easy stuff.
COSC160: Data Structures: Lists and Queues
September 29 – Stacks and queues
CSCI-255 LinkedList.
Chapter 15 Lists Objectives
CS 1114: Implementing Search
Stacks and Queues.
Queues Queues Queues.
Programming Abstractions
Stack and Queue APURBO DATTA.
Queues Chapter 4.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Monday, February 26, 2018 Announcements… For Today…
Introduction to Data Structure
Data Structures and Database Applications Queues in C#
HW-6 Deadline Extended to April 27th
i206: Lecture 11: Stacks, Queues
CMSC 341 Lecture 5 Stacks, Queues
structures and their relationships." - Linus Torvalds
Queues.
Stacks, Queues, and Deques
Queues 11/22/2018 6:47 AM 5.2 Queues Queues Dr Zeinab Eid.
Stacks, Queues, and Deques
Java Collections Framework
CSC 143 Queues [Chapter 7].
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Data Structures and Algorithms for Information Processing
Queues Jyh-Shing Roger Jang (張智星)
QUEUE Visit for more Learning Resources Free Powerpoint Templates.
CE 221 Data Structures and Algorithms
Using a Queue Chapter 8 introduces the queue data type.
Using a Queue Chapter 8 introduces the queue data type.
Stacks, Queues, and Deques
CSCS-200 Data Structure and Algorithms
Queues and Priority Queue Implementations
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
structures and their relationships." - Linus Torvalds
Data Structures & Programming
Presentation transcript:

Queue ADT (Abstract Data Type) N … 3 2 1

What is a Queue? A queue is an ordered collection, or list, of items that can only be modified by removing items at the beginning or adding items to the end Items are processed on a first come/first serve basis There is no access to the middle of the list (no “cutting in line”) Real life examples: Waiting on a grocery store check-out line (actual physical line) Waiting in a reception room or for a table in a restaurant (“virtual” line)

Queues in the abstract Sometimes referred to as a “FIFO” Stands for “first-in/first-out” A stack would be a “LIFO” Some definitions: Enqueue: add an item to the end Dequeue: remove an item from the beginning

Abstract Data Type (ADT) for a Queue QueueADT requires that a program implementing a queue contain certain minimum core capabilities: Elements must be maintained in an ordered list Facilities must be provided to both remove first item in list (dequeue) and add new items to the end of the list (enqueue) Individual elements in the queue can be any valid data type (or collection of data types) Other possible capabilities: Query the queue for contents, length, … Clear or empty the queue Limit or expand the size of the queue

Queue Representations Using an Array Using a Linked List 1 2 3 4 … N-1 1 2 … N null

Array Implementation of Queue Use an array to store data elements Advantages: Easy to access Natural ordering Size Limitation Array is fixed size Number of entries is limited unless special measures are taken 1 N-1 first last 2

Queue Array Implementation with wrap-around Starting index issue Problem: As items are dequeued, empty cells show up at the beginning of the array Solution: implement a wrap- around capability When the last element is filled, start over at the beginning normal configuration 1 2 first last with wrap-around 1 2 first last

Array Implementation of Queue in C++ qarray.c Simple implementation of QueueADT using C++ Stores user provided integers in a queue Features: Fixed size array Implements wrap-around feature Basic functionality: enqueue, dequeue, and display methods main.c - simple wrapper for testing

Linked List Implementation of Queue Use a linked list to store data elements Advantages: Virtually unlimited number of elements No “wrap-around” worries Potential issues More complex coding Need to manage pointers and data containers On-the-fly memory allocation/deallocation More memory required (data plus pointers) Most likely slower than array implementation 1 2 … N null

Queue Linked List Implementation in C++ qllist.c Simple implementation of QueueADT using C++ Stores user provided integers in a queue Features: Unlimited queue size Basic functionality: enqueue, dequeue, and display methods main.c - simple wrapper for testing (same as for array implementation)

Final Considerations What about more complex data (not just integers)? The integers can be pointers to other data containers (classes, structs …) Generalize by making a template Which implementation is better? Answer is: “it depends…” If a fixed size queue is acceptable, probably an array For example: large quantities of predictable, streaming data that requires buffering (audio or video streaming from the internet) If managing random, or unpredictable, data, a linked list might be better Particularly if speed or memory is less of an issue Lists of names, addresses …