Using a different comparison function: greater : Priority Queue « Data Structure « C++






Using a different comparison function: greater

Using a different comparison function: greater


#include <iostream>
#include <queue>
#include <functional>
using namespace std;

int main()
{
  priority_queue<int, vector<int>, greater<int> > q;
  
  q.push(1);
  q.push(3);
  q.push(4);

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

  return 0;
}

           
       








Related examples in the same category

1.Demonstrate a priority_queue.Demonstrate a priority_queue.
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