Sorting a vector in descending order

Actually, the first one is a bad idea. Use either the second one, or this:

struct greater
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};

std::sort(numbers.begin(), numbers.end(), greater());

That way your code won’t silently break when someone decides numbers should hold long or long long instead of int.

Leave a Comment