C++ examples for STL:priority_queue
Push value to queue and pop value out of priority_queue
#include <iostream> #include <queue> // priority_queue adapter definition using namespace std; int main() // w w w . j a v a 2 s . c o m { priority_queue< double > priorities; // create priority_queue // push elements onto priorities priorities.push( 3.2 ); priorities.push( 9.8 ); priorities.push( 5.4 ); cout << "Popping from priorities: "; // pop element from priority_queue while ( !priorities.empty() ) { cout << priorities.top() << ' '; // view top element priorities.pop(); // remove top element } cout << endl; }