5

I need to store numbers in a queue in increasing order.
I used priority queue which stores higher value first, that is in decreasing order.

priority_queue<int>q;

Is it possible to order them increasing ?
What can i do to make the data order to be increasing ?

Pablo
  • 65
  • 1
  • 1
  • 5

2 Answers2

14

To store value in increasing order you just need to change the declaration of the priority queue :

priority_queue<int, vector<int>, greater<int> >q;
Ali Akber
  • 3,670
  • 3
  • 26
  • 40
5

Just in case, in C++14 you can do:

priority_queue<int, vector<int>, greater<>> q;

You can avoid greater<int>. That is the new way. for more information, see What are transparent comparators?.

Community
  • 1
  • 1
Germán Diago
  • 7,473
  • 1
  • 36
  • 59