When I am writing code, I was confused by the usage of the functor.
If I want to sort a sequence of integers in descending order, I have to put greater<int> in the third parameter of sort, e.g. sort(v.begin(), v.end(), greater<int>());.
But when dealing with priority_queue, I have to put less<int> in the third parameter to get a maximum-top-heap, e.g. priority_queue< int, vector <int>, less<int> > heap;.
So My question is that why we get the same ascending relation using two different functor?
Could anyone explain why this is happening? Better use the source code from the implement of STL to make me clear.
Apologize for my poor English.
Thanks a lot!
std::greater<int>? I think you mean descending order ? If that's the case your question won't make sense