Data Structures Using C++

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

Templates in C++ Template function in C++ makes it easier to reuse classes and functions. A template can be viewed as a variable that can be instantiated.
Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
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.
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.
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials Stack and Queues.
ADT Queue 1. What is a Queue? 2. STL Queue 3. Array Implementation of Queue 4. Linked List Implementation of Queue 5. Priority Queue.
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.
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.
Jerry Lebowitz.  Stacks  Queues 3 C++ Programming: From Problem Analysis to Program Design, Sixth Edition.
Chapter 5 Queues Modified. Chapter Scope Queue processing Comparing queue implementations 5 - 2Java Software Structures, 4th Edition, Lewis/Chase.
DATA STRUCTURE & ALGORITHMS
Chapter 7 Queues. © 2005 Pearson Addison-Wesley. All rights reserved7-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
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.
CHAPTER 8 Lists. 2 A list is a linear collection Adding and removing elements in lists are not restricted by the collection structure We will examine.
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.
Chapter 18: Stacks and Queues
Chapter 18: Stacks and Queues
1 Queues (Walls & Mirrors - Chapter 7). 2 Overview The ADT Queue Linked-List Implementation of a Queue Array Implementation of a Queue.
Data Structures Using C++ 2E
Chapter 17: Stacks and Queues
Data Structures Using C++ 2E Chapter 7 Stacks. Data Structures Using C++ 2E2 Objectives Learn about stacks Examine various stack operations Learn how.
TK1924 Program Design & Problem Solving Session 2011/2012 L6: Queues.
1 CS 132 Spring 2008 Chapter 8 Queues. 2 Queue A data structure in which the elements are added at one end, called the rear, and deleted from the other.
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)
Chapter 18: Stacks and Queues
1 Chapter 7 Stacks and Queues. 2 Stack ADT Recall that ADT is abstract data type, a set of data and a set of operations that act upon the data. In a stack,
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.
Lab 7 Queue ADT. OVERVIEW The queue is one example of a constrained linear data structure. The elements in a queue are ordered from least recently added.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 19: 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.
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.
Data Structures Using C++1 Chapter 7 Stacks. Data Structures Using C++2 Chapter Objectives Learn about stacks Examine various stack operations Learn how.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 18: Stacks and Queues.
1 Chapter 17: Stacks and Queues Learn about stacks Examine various stack operations Learn how to implement a stack as an array Learn how to implement a.
1 C++ Plus Data Structures Nell Dale Chapter 5 Linked Structures Modified from the slides by Sylvia Sorkin, Community College of Baltimore County - Essex.
Chapter 17: Stacks and Queues. Objectives In this chapter, you will: – Learn about stacks – Examine various stack operations – Learn how to implement.
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.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
Circular Queues Maitrayee Mukerji. Queues First In – First Out (FIFO) The first element to be inserted is the first one to be retrieved Insertion at one.
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.
Chapter 17: Stacks and Queues Java Programming: Program Design Including Data Structures Program Design Including Data Structures.
Data Structures Using C++ 2E
Data Structures Using C++ 2E
Data Structures Using C, 2e
CS505 Data Structures and Algorithms
Queues Chapter 4.
QUEUES.
CC 215 Data Structures Queue ADT
Stacks and Queues.
Queues Chapter 4.
CSCE 3110 Data Structures & Algorithm Analysis
CMSC 341 Lecture 5 Stacks, Queues
DATA STRUCTURE QUEUE.
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.
Queues Jyh-Shing Roger Jang (張智星)
CSC 248 – fundamentals of Data structure
Data Structures Using C++ 2E
Data Structures & Programming
Presentation transcript:

Data Structures Using C++ Chapter 8 Queues Data Structures Using C++

Data Structures Using C++ Chapter Objectives Learn about queues Examine various queue operations Learn how to implement a queue as an array Learn how to implement a queue as a linked list Data Structures Using C++

Data Structures Using C++ Chapter Objectives Discover queue applications Examine the STL class queue Discover priority queues Data Structures Using C++

Data Structures Using C++ Queues Definition: data structure in which the elements are added at one end, called the rear, and deleted from the other end, called the front or first First In First Out (LIFO) data structure Data Structures Using C++

Basic Operations on a Queue initializeQueue: Initializes the queue to an empty state destroyQueue: Removes all the elements from the queue, leaving the queue empty isEmptyQueue: Checks whether the queue is empty. If the queue is empty, it returns the value true; otherwise, it returns the value false Data Structures Using C++

Basic Operations on a queue isFullQueue: Checks whether the queue is full. If the queue is full, it returns the value true; otherwise, it returns the value false front: Returns the front (first) element of the queue; the queue must exist back: Returns the front (first) element of the queue; the queue must exist Data Structures Using C++

Basic Operations on a queue addQueue: Adds a new element to the rear of the queue; the queue must exist and must not be full deleteQueue: Removes the front element of the queue; the queue must exist and must not be empty Data Structures Using C++

Data Structures Using C++ Queues as Arrays Data Structures Using C++

Data Structures Using C++ Queues as Arrays Data Structures Using C++

Data Structures Using C++ Circle Queue Data Structures Using C++

Data Structures Using C++ Queues as Arrays Data Structures Using C++

Data Structures Using C++ Queues as Arrays Data Structures Using C++

Data Structures Using C++ Queues as Arrays Data Structures Using C++

Data Structures Using C++ Queues as Arrays Data Structures Using C++

Data Structures Using C++ Queues as Arrays Data Structures Using C++

Data Structures Using C++ Queues as Arrays Data Structures Using C++

Data Structures Using C++ Queues as Arrays Data Structures Using C++

UML Diagram of the class queueType Data Structures Using C++

Data Structures Using C++ Initialize Queue Definition of the function initializeQueue: template<class Type> void queueType<Type>::initializeQueue() { queueFront = 0; queueRear = maxQueueSize - 1; count = 0; } Data Structures Using C++

Empty Queue and Full Queue template<class Type> bool queueType<Type>::isEmptyQueue() { return (count == 0); } bool queueType<Type>::isFullQueue() return (count == maxQueueSize); Data Structures Using C++

Data Structures Using C++ Destroy Queue template<class Type> void queueType<Type>::destroyQueue() { queueFront = 0; queueRear = maxQueueSize - 1; count = 0; } Data Structures Using C++

Data Structures Using C++ front and back template<class Type> Type queueType<Type>::front() { assert(!isEmptyQueue()); return list[queueFront]; } template<class Type> Type queueType<Type>::back() { assert(!isEmptyQueue()); return list[queueRear]; } Data Structures Using C++

Data Structures Using C++ Add Queue template<class Type> void queueType<Type>::addQueue(const Type& newElement) { if(!isFullQueue()) queueRear = (queueRear + 1) % maxQueueSize; //use the mod //operator to advance queueRear //because the array is circular count++; list[queueRear] = newElement; } else cerr<<"Cannot add to a full queue."<<endl; Data Structures Using C++

Data Structures Using C++ Delete Queue template<class Type> void queueType<Type>::deleteQueue() { if(!isEmptyQueue()) count--; queueFront = (queueFront + 1) % maxQueueSize; //use the mod //operator to advance queueFront //because the array is circular } else cerr<<"Cannot remove from an empty queue."<<endl; Data Structures Using C++

Constructor and Destructor Creates an array of the size specified by the user Default value is 100 Initializes queueFront queueRear to indicate that the queue is empty Destructor When queue object goes out of scope, destructor reallocates memory occupied by the array that stores the queue elements Data Structures Using C++

Data Structures Using C++ Linked Queue as an ADT Data Structures Using C++

Empty, Full, and Destroy Queue Queue is empty if queueFront is NULL Queue is full only if we run out of memory Destroy queue removes all elements of the queue Data Structures Using C++

Data Structures Using C++ addQueue Adds a new element to the end of the queue Access the pointer queueRear to implement addQueue Data Structures Using C++

Front, Back, and Delete Queue If queue is nonempty: operation front returns the first element of the queue operation back returns the last element of the queue operation deleteQueue removes the first element of the queue If queue is empty: function front terminates the program function back terminates the program Data Structures Using C++

STL class queue (Queue Container Adapter) Data Structures Using C++

Data Structures Using C++ Priority Queue FIFO rules of a queue are relaxed Customers or jobs with higher priority are pushed to front of queue To implement: use an ordinary linked list, which keeps the items in order from the highest to lowest priority use a treelike structure Data Structures Using C++

Data Structures Using C++ Application of Queues Data Structures Using C++

Data Structures Using C++ Application of Queues Data Structures Using C++

Data Structures Using C++ Application of Queues Data Structures Using C++

Application of Queues: waitingCustomerQueueType Data Structures Using C++

Data Structures Using C++ Poisson Distribution Data Structures Using C++

Data Structures Using C++ Chapter Summary Queue Data Structure Restricted Version of arrays and linked list Basic operations First In First Out (FIFO) Queues Implemented as Arrays Data Structures Using C++

Data Structures Using C++ Chapter Summary Queues Implemented as Linked Lists STL class queue Priority Queues Application of Queues Data Structures Using C++