Mega Code Archive

 
Categories / C++ Tutorial / Queue Stack
 

Get top() from priority_queue

#include <iostream> #include <string> #include <queue> #include <stack> using namespace std; int main() {   priority_queue<int> pq;   cout << "A priority_queue for integers.\n";   pq.push(1);   pq.push(3);   pq.push(4);   pq.push(2);   cout << "retrieve those values in priority order.\n";   while(!pq.empty()) {     cout << "Popping ";     cout << pq.top() << "\n";     pq.pop();   }   cout << endl;   return 0; }