How to sort a vector by descending elements using standard algorithms?

    2 answers 2

    std::sort(v.rbegin(), v.rend()); 

      I think it will be clear:

       std::sort(my_vect.rbegin(), my_vect.rend()); or std::sort(my_vect.begin(), my_vect.end(), std::greater<type>); 

      where type is the type of vector elements (int, double, string, etc.)

      • 3
        std :: greater <int> () - dzhioev