Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

STL function like sort

Tags:

c++

stl

Is there a function like std::sort that instead of sorting in increasing order, sorts in decreasing order?

like image 359
snoopy Avatar asked Feb 16 '26 13:02

snoopy


1 Answers

Yes. It's called std::sort.

sort has an overload that takes a functor that defines the sort order as a third parameter. If you want decreasing order, then pass it std::greater<T>(), where T is your type.

like image 88
Nicol Bolas Avatar answered Feb 19 '26 03:02

Nicol Bolas