Copyright © 2011 - Curt Hill STL Priority Queue A Heap-Like Adaptor Class.

Slides:



Advertisements
Similar presentations
Chapter 19 Standard Template Library. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives Iterators Constant and mutable.
Advertisements

Vectors, lists and queues
Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Chapter 6: Priority Queues (Heaps) Priority Queue ADT Heap Implementation CS 340 Page 100 Heap Applications Leftist Heaps.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
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.
More on the STL vector list stack queue priority_queue.
Standard Template Library (STL) Overview – Part 1 Yngvi Bjornsson.
Priority Queues Briana B. Morrison Adapted from Alan Eugenio Sell100IBM$122 Sell300IBM$120 Buy500IBM$119 Buy400IBM$118.
Rossella Lau Lecture 11, DCO20105, Semester A, DCO Data structures and algorithms  Lecture 11: Queue & Priority Queue  Basic operations.
. STL: C++ Standard Library. Main Ideas u General purpose: generic data structures & algorithms, templates u Flexibility: Allows for many combinations.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
1 Priority Queues (Heaps)  Sections 6.1 to The Priority Queue ADT  DeleteMin –log N time  Insert –log N time  Other operations –FindMin  Constant.
Templates and the STL.
CSIS 123A Lecture 12 Templates. Introduction  C++ templates  Allow very ‘general’ definitions for functions and classes  Type names are ‘parameters’
Dr. Yingwu Zhu STL Vector and Iterators. STL (Standard Template Library) 6:14:43 AM 2 A library of class and function templates Components: 1. Containers:
 2003 Prentice Hall, Inc. All rights reserved stack Adapter stack –Header –Insertions and deletions at one end –Last-in, first-out (LIFO) data.
1 Stacks Stack Examples Stack API More Examples/Uses Base Conversion Activation Records RPN Implementing a Stack Stacks.
Containers Overview and Class Vector
1 EE 355 Unit 14 A-Star Algorithm & Heaps/Priority Queues Mark Redekopp.
CNS  Sequences  vector,deque,list,(string),forward_list  Container Adapters  queue, stack, priority_queue  Associative Containers  set, unordered_set.
Templates code reuse - inheritance - template classes template classes - a class that is not data-type specific - eg. a class of Array of any type - intArray,
Friends & Standard Template Library CSCI3110 Advanced Data Structures Lecturer: Dr. Carroll and Nan Chen.
Tracing through E01, question 9 – step 1 // p02.cc P. Conrad, for CISC181 07S // Exam question for E01 #include using namespace std; void mysteryFunction(int.
Introduction to the Standard Template Library (STL) A container class holds a number of similar objects. Examples: –Vector –List –Stack –Queue –Set –Map.
Queue Queue – First In / First Out (FIFO) data structure that supports two operations: push for adding new element at the end of the queue pop for removing.
 2003 Prentice Hall, Inc. All rights reserved.m ECE 2552 Dr. Këpuska based on Dr. S. Kozaitis Summer Chapter 15 - Class string and String Stream.
CMSC 341 Deques, Stacks and Queues. 2/20/20062 The Double-Ended Queue ADT A Deque (rhymes with “check”) is a “Double Ended QUEue”. A Deque is a restricted.
Lecture 7 : Intro. to STL (Standard Template Library)
The Standard Template Library Container Classes Version 1.0.
Copyright © 2009 – Curt Hill Standard Template Library An Introduction.
1 Queues Queue API Application: Radix Sort Implementation: Using Deque Using Deque Circular Array Circular Array Priority Queue Priority Queue API Implementation.
Midterm Review Linear list Stack queue. What is a data structure What is an abstract data type.
More STL Container Classes ECE Last Time Templates –Functions –Classes template void swap_val (VariableType &a, VariableType &b) { VariableType.
1 The Standard Template Library Drozdek Section 3.7.
Glenn Stevenson CSIS 113A MSJC CSIS 123A Lecture 3 Vectors.
Properties: -The value in each node is greater than all values in the node’s subtrees -Complete tree! (fills up from left to right) Max Heap.
Templates. C++ 2 Outline Function templates  Function template definition  Function template overloading Class templates  Class template definition.
C++ Templates 1. Why Use Templates? C++ requires variables, functions, classes etc with specific data types. However, many algorithms (quicksort for example)
CSCI-383 Object-Oriented Programming & Design Lecture 30.
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
Copyright © Curt Hill Generic Functions Separating Data Type from Logic.
Unit VI.  C++ templates are a powerful mechanism for code reuse, as they enable the programmer to write code (classes as well as functions) that behaves.
1 The Standard Template Library The STL is a collection of Container classes These are class templates for containers. A container is an object that stores.
1 Priority Queues (Heaps)  Sections 6.1 to Priority Queues  Regular queues which supports –First In, First Out –Enqueue(): add a new element.
Object-Oriented Programming (OOP) Lecture No. 41
Introduction to olympic programming
CSCI 104 Priority Queues / Heaps
Data Structures and Algorithms
Priority Queues (Heaps)
Standard Template Library (STL)
Priority Queues Sections 6.1 to 6.5.
Prof. Michael Neary Lecture 7: The STL Prof. Michael Neary
An Introduction to Pointers
Lecture 13 – Heaps Container Adapters priority_queue – impl. with heap
priority_queue<T>
Pointers & Functions.
Templates. Templates Example: Swap Template Mechanism.
Introduction to Programming
Mutable Data (define mylist (list 1 2 3)) (bind ((new (list 4)))
Copyright © – Curt Hill STL List Details Copyright © – Curt Hill.
Lecture 8 : Intro. to STL (Standard Template Library)
STL Библиотека стандартных шаблонов
STL (Standard Template Library)
Pointers & Functions.
C++ Programming: chapter 10 – STL
Standard Template Library
8.3 Vectors Copyright © 2008 Pearson Addison-Wesley. All rights reserved. 1.
Abstract Data Types (ADTs)
Presentation transcript:

Copyright © Curt Hill STL Priority Queue A Heap-Like Adaptor Class

Copyright © Curt Hill Introduction Like the STL stacks and queues this is an adaptor It may use a vector or deque –Vector is the default It uses the heap organization with the vector or deque

Generalities The include is the same as queue: #include The declaration is: priority_queue pq; –Requires that Acls is suitable for comparison You may also be explicit priority_queue, less > pq; This require include for vector Copyright © Curt Hill

Commentary The second template parameter is the actual container class You may substitute greater for less This makes the lowest value to be the next one obtained, rather than the greatest Copyright © Curt Hill

Methods The usual standard methods exist The queue specific ones that we are interested in are: –push –pop – void function –top – gives the top of the heap –empty – same as size() == 0 Copyright © Curt Hill

Example Copyright © Curt Hill #include using namespace std; int main () { priority_queue mypq; mypq.push(30); mypq.push(100); mypq.push(25); mypq.push(40); cout << "Popping out elements..."; while (!mypq.empty()) { cout << " " << mypq.top(); mypq.pop(); } cout << endl; return 0; } Popping out elements