Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues.

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

QUEUE Education is the best friend. An educated person is respected everywhere. Education beats the beauty and the youth. Chanakya.
Queues. Queue Definition Ordered list with property: All insertions take place at one end (tail) All insertions take place at one end (tail) All deletions.
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.
Queues CS 308 – Data Structures. What is a queue? It is an ordered group of homogeneous items of elements. Queues have two ends: –Elements are added at.
1 Data Structures CSCI 132, Spring 2014 Lecture 8 Implementing Queues.
CHAPTER 4 QUEUE CSEB324 DATA STRUCTURES & ALGORITHM.
What is a Queue? n Logical (or ADT) level: A queue is an ordered group of homogeneous items (elements), in which new elements are added at one end (the.
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.
Queues CS 3358 – Data Structures. What is a queue? It is an ordered group of homogeneous items of elements. Queues have two ends: – Elements are added.
ADT Queue 1. What is a Queue? 2. STL Queue 3. Array Implementation of Queue 4. Linked List Implementation of Queue 5. Priority Queue.
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.”
LINKED QUEUES P LINKED QUEUE OBJECT Introduction Introduction again, the problem with the previous example of queues is that we are working.
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.
Chapter3 QUEUES.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
Data Structure Dr. Mohamed Khafagy.
Queue Overview Queue ADT Basic operations of queue
Data Structures Chapter 3 Queues Andreas Savva. 2 Queues A data structure modeled after a line of people waiting to be served. A data structure modeled.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
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.
Data Structures Chapter 4 Linked Stacks and Queues Andreas Savva.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Topic 3 Basic Data Structures continued CSE1303 Part A Data Structures and Algorithms.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A4 – Basic Data Structures – Continued (Queues)
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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 18: Stacks and.
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 (Walls & Mirrors - Chapter 7). 2 Overview The ADT Queue Linked-List Implementation of a Queue Array Implementation of a Queue.
Data Structures Chapter 2 Stacks Andreas Savva. 2 Stacks A stack is a data structure in which all insertions and deletions of entries are made at one.
Object Oriented Data Structures
Queues Chapter 3. Objectives Introduce the queue abstract data type. – Queue methods – FIFO structures Discuss inheritance in object oriented programming.
Copyright © 2012 Pearson Education, Inc. Chapter 18: Stacks And Queues.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues.
Data Structures Using Java1 Chapter 7 Queues. Data Structures Using Java2 Chapter Objectives Learn about queues Examine various queue operations Learn.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
Data Structures Using C++
Introduction to Stacks Chapter 2. Objectives Introduce abstract data types. Discuss implementation types. – Static – Dynamic – Contiguous Introduce the.
Stacks And Queues Chapter 18.
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.
EC-211 DATA STRUCTURES LECTURE 9. Queue Data Structure An ordered group of homogeneous items or elements. Queues have two ends: – Elements are added at.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 18: Stacks and Queues.
Kruse/Ryba ch041 Linked Stacks and Queues Pointers and Linked Structures Linked Stacks Linked Stacks with Safeguards Linked Queues Application: Polynomials.
1 Data Structures CSCI 132, Spring 2014 Lecture 6 Applications using Stacks.
Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues.
1 Queues Queue API Application: Radix Sort Implementation: Using Deque Using Deque Circular Array Circular Array Priority Queue Priority Queue API Implementation.
1 Data Structures CSCI 132, Spring 2016 Notes13 Queues as Linked Lists, Polynomial Arithmetic.
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,
1 Data Structures CSCI 132, Spring 2014 Lecture 7 Queues.
1 Data Structures CSCI 132, Spring 2016 Notes_ 5 Stacks.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 18: Stacks and Queues.
CS505 Data Structures and Algorithms
CC 215 Data Structures Queue ADT
Stacks and Queues.
Basic Data Structures – Continued (Queues)
Linked Stacks and Queues
CMSC 341 Lecture 5 Stacks, Queues
Queues.
تهیه کنندگان مهری بابائی،گیتا جوادی رضا امید ملایری ،ناصر بهمدی
Queues.
Queues Jyh-Shing Roger Jang (張智星)
Visit for more Learning Resources
Queues.
Queues The content for these slides was originally created by Gerard Harrison. Ported to C# by Mike Panitz.
Presentation transcript:

Kruse/Ryba ch031 Object Oriented Data Structures Queues Implementations of Queues Circular Implementation of Queues

Kruse/Ryba ch032 Queues Print Queues Registration Lines Movie Lines Job Queues Bank Lines

Kruse/Ryba ch033 Basic Idea A queue can hold an arbitrary number of elements, but you place new elements in at one end (back) and remove elements from the other (front) end. Sometimes called a FIFO structure, for F irst I n, F irst O ut.

Kruse/Ryba ch034 ADT - Queue Create the queue, leaving it empty Test whether the queue is empty Append a new entry onto the back of the queue, if possible Serve (delete) the entry from the front of the queue, if not empty Retrieve front element of queue, if not empty A queue of elements of type T is a finite sequence of elements of T, together with the operations:

Kruse/Ryba ch035 Partial Implementation (Text) typedef char QueueEntry; class Queue { Queue(); bool empty() const; ErrorCode append(const QueueEntry & item); ErrorCode serve(); ErrorCode retrieve(QueueEntry & item) const; }; //end Queue

Kruse/Ryba ch036 Extended Queue class ExtendedQueue: public Queue { public: bool full() const; int size() const; void clear(); ErrorCode serveAndRetrieve(QueueEntry & item); }; //end ExtendedQueue

Kruse/Ryba ch037 Inheritance Methods: Queue append serve retrieve empty Data members Methods: Queue append serve retrieve empty size clear full serveAndRetrieve Data members Additional Data Members Inheritance Queue ExtendedQueue

Kruse/Ryba ch038 Implementations Physical model Linear array Circular array Circular array with flag Circular array with count variable Circular array with tombstones

Kruse/Ryba ch039 Circular Implementation 0 1 front rear n n-1

Kruse/Ryba ch0310 Circular Arrays in C++ i = ((i + 1) == max) ? 0 : (i + 1); if((i + 1) == max) i = 0; else i = i + 1; i = (i + 1) % max;

Kruse/Ryba ch0311 Class Implementation const int MAXQUEUE= 10; //small value for testing class Queue { public: Queue(); bool empty() const; ErrorCode serve(); ErrorCode append(const QueueEntry & item); ErrorCode retrieve(QueueEntry & item)const; protected: int count; int front, rear; QueueEntry entry[MAXQUEUE]; };

Kruse/Ryba ch0312 Constructor Queue::Queue() /*Post: The Queue is initialized to be empty.*/ { count = 0; rear = MAXQUEUE - 1; front = 0; } Queue::Queue() : count(0), rear(MAXQUEUE-1), front(0) /*Post: The Queue is initialized to be empty.*/ { // nothing needed here }

Kruse/Ryba ch0313 empty() bool Queue::empty() const /*Post: Return true if the Queue is empty, otherwise return false.*/ { return count == 0; }

Kruse/Ryba ch0314 append() // Post: item is added to the rear of the Queue. // If the Queue is full return an Error_code of // overflow and leave the Queue unchanged. ErrorCode Queue::append(const QueueEntry &item) { if (count >= MAXQUEUE) return overflow; count++; rear = ((rear + 1) == maxqueue) ? 0 : (rear + 1); entry[rear] = item; return success; } frontrearitem

Kruse/Ryba ch0315 serve() // Post: The front of the Queue is removed. // If the Queue is empty return an ErrorCode // of underflow. ErrorCode Queue::serve() { if (count <= 0) return underflow; count--; front = ((front + 1) == MAXQUEUE) ? 0 : (front + 1); return success; } frontrear

Kruse/Ryba ch0316 serve() // Post: The front of the Queue is removed. // If the Queue is empty return an ErrorCode // of underflow. ErrorCode Queue::serve() { if (count <= 0) return underflow; count--; front = ((front + 1) == MAXQUEUE) ? 0 : (front + 1); return success; } rear new front

Kruse/Ryba ch0317 retrieve() // Post: The front of the Queue retrieved to the // output parameter item. If the Queue is empty // return an ErrorCode of underflow ErrorCode Queue::retrieve(QueueEntry &item) const { if (count <= 0) return underflow; item = entry[front]; return success; } frontrear myItem QueueEntry myItem; myQueue.retrieve(myItem); front

Kruse/Ryba ch0318 retrieve() // Post: The front of the Queue retrieved to the // output parameter item. If the Queue is empty // return an ErrorCode of underflow ErrorCode Queue::retrieve(QueueEntry &item) const { if (count <= 0) return underflow; item = entry[front]; return success; } frontrear myItem QueueEntry myItem; myQueue.retrieve(myItem); rear

Kruse/Ryba ch0319 Chapter 3 Closes