Standard C++ Library Class Reference
#include <string>
#include <iostream.h>
int main(void)
{
// Make a priority queue of int using a vector container
priority_queue<int, vector<int>, less<int>, allocator> pq;
// Push a couple of values
pq.push(1);
pq.push(2);
// Pop a couple of values and examine the ends
cout << pq.top() << endl;
pq.pop();
cout << pq.top() << endl;
pq.pop();
// Make a priority queue of strings using a deque container
priority_queue<string, deque<string>, less<string>, allocator>
pqs;
// Push on a few strings then pop them back off
int i;
for (i = 0; i < 10; i++)
{
pqs.push(string(i+1,'a'));
cout << pqs.top() << endl;
}
for (i = 0; i < 10; i++)
{
cout << pqs.top() << endl;
pqs.pop();
}
// Make a priority queue of strings using a deque
// container, and greater as the compare operation
priority_queue<string,deque<string>, greater<string>,
allocator> pgqs;
// Push on a few strings then pop them back off
for (i = 0; i < 10; i++)
{
pgqs.push(string(i+1,'a'));
cout << pgqs.top() << endl;
}
for (i = 0; i < 10; i++)
{
cout << pgqs.top() << endl;
pgqs.pop();
}