Demonstrate a priority_queue. : Priority Queue « Data Structure « C++






Demonstrate a priority_queue.

Demonstrate a priority_queue.
#include <iostream>
#include <queue>
using namespace std;

int main()
{
  priority_queue<int> queueObject;
  
  queueObject.push(1);
  queueObject.push(3);
  queueObject.push(4);

  while(!queueObject.empty()) {
    cout << "Popping ";
    cout << queueObject.top() << endl;
    queueObject.pop();
  }

  return 0;
}

           
       








Related examples in the same category

1.Using a different comparison function: greaterUsing a different comparison function: greater
2.Storing class objects in a priority_queue.Storing class objects in a priority_queue.
3.PriorityQueue: push, pop and topPriorityQueue: push, pop and top