I have an array containing multiple integers, is there a common way for sorting it from high to low?
+2
A:
Pass a comparator to the sort routine that reverses the normal comparison.
Ignacio Vazquez-Abrams
2010-10-11 18:04:28
does he even have a sort routine?
zaczap
2010-10-11 18:05:27
@zaczap: Dunno. But that's how to do it.
Ignacio Vazquez-Abrams
2010-10-11 18:06:24
@zaczap: There is a standard one
Martin York
2010-10-11 18:07:09
@Martin: more than standard one, for that matter (`std::sort` and `std::stable_sort` to name two).
Jerry Coffin
2010-10-11 18:09:41
+26
A:
#include <algorithm>
#include <functional>
int arr[ 5 ] = { 4, 1, 3, 2, 5 };
std::sort( arr, arr + 5, std::greater< int >() );
usta
2010-10-11 18:05:03