Why the priority_queue top() Max number?

template <class T, class Container = vector<T>,
class Compare = less<typename Container::value_type> > class priority_queue;

I think the priority should be the min number.Because the compare default less

Like the set
template < class T, // set::key_type/value_type
class Compare = less<T>, // set::key_compare/value_compare
class Alloc = allocator<T> // set::allocator_type
> class set;
> I think the priority should be the min number.Because the compare default less
You are wrong.
http://www.cplusplus.com/reference/queue/priority_queue/pop/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// priority_queue::push/pop
#include <iostream>       // std::cout
#include <queue>          // std::priority_queue

int main ()
{
  std::priority_queue<int> mypq;

  mypq.push(30);
  mypq.push(100);
  mypq.push(25);
  mypq.push(40);

  std::cout << "Popping out elements...";
  while (!mypq.empty())
  {
     std::cout << ' ' << mypq.top();
     mypq.pop();
  }
  std::cout << '\n';

  return 0;
}



Popping out elements... 100 40 30 25
Topic archived. No new replies allowed.