lecture09STLheap - STL priority_queue and Heap Code from...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
STL priority_queue and Heap Code from the STL Examples of its use
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
STL priority_queue class Default constructor Initializing constructor bool empty() const; void pop(); void push(); size_type size() const; const value_type& top() const; Class encapsulates internal vector storage, or optionally, a deque Max PQ
Background image of page 2
~cse331/web/Examples/Heap Multiple program examples
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example STL #include <queue> #include <iostream> #include <algorithm> using namespace std; int main ( ) { priority_queue<int> PQ; cout << "\n+ STL (max) priority_queue example ++\n";
Background image of page 4
if ( PQ.empty() ) cout << "\nPQ is empty.\n"; PQ.push(34); PQ.push(13); PQ.push(28); cout << "\nPQ.size() = " << PQ.size() << endl; cout << "\nPQ.top() = " << PQ.top() << endl; PQ.pop(); cout << "\nPQ.top() = " << PQ.top() << endl; PQ.push(50); PQ.push(25); PQ.push(50); PQ.pop(); cout << "\nPQ.top() = " << PQ.top() << endl << endl; PQ is empty. PQ.size() = 3
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/25/2008 for the course CSE 331 taught by Professor M.mccullen during the Spring '08 term at Michigan State University.

Page1 / 11

lecture09STLheap - STL priority_queue and Heap Code from...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online