Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Copyright © 2011 - Curt Hill STL Priority Queue A Heap-Like Adaptor Class."— Presentation transcript:

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

2 Copyright © 2011 - 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

3 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 © 2011 - Curt Hill

4 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 © 2011 - Curt Hill

5 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 © 2011 - Curt Hill

6 Example Copyright © 2011 - 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... 100 40 30 25


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

Similar presentations


Ads by Google