C++ examples for STL:priority_queue
Test priority_queue method: push(), empty(), top(), pop()
#include <iostream> #include <string> #include <queue> #include <stack> using namespace std; int main()/*from w w w. ja v a2 s .com*/ { // Demonstrate priority_queue. priority_queue<int> pq; cout << "Demonstrate a priority_queue for integers.\n"; cout << "Pushing 1, 3, 4, 2.\n"; pq.push(1); pq.push(3); pq.push(4); pq.push(2); cout << "Now, retrieve those values in priority order.\n"; while(!pq.empty()) { cout << "Popping "; cout << pq.top() << "\n"; pq.pop(); } cout << endl; return 0; }