tags:

views:

209

answers:

2

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
does he even have a sort routine?
zaczap
@zaczap: Dunno. But that's how to do it.
Ignacio Vazquez-Abrams
@zaczap: There is a standard one
Martin York
@Martin: more than standard one, for that matter (`std::sort` and `std::stable_sort` to name two).
Jerry Coffin
+26  A: 
#include <algorithm>
#include <functional>
int arr[ 5 ] = { 4, 1, 3, 2, 5 };
std::sort( arr, arr + 5, std::greater< int >() );
usta