C++ vector sort by sort()

Description

C++ vector sort by sort()

#include <iostream> 
#include <array> 
#include <vector> 
#include <ios> 

using namespace std; 

bool Descending(int first, int second) 
{ 
        return first > second; 
} 

int main(int argc, char *argv [])
{   //  www .ja  v  a 2 s. c o m

        using MyVector = vector<int>; 
        MyVector myVector = { 10, 1, 2, 3, 4 ,44,-2,8,7,6,5,4,3,3,2,2,2,34,}; 
  
        sort(myVector.begin(), myVector.end(), Descending); 
        for (auto& value : myVector) 
        { 
                cout << value << endl; 
        } 
  
        sort(myVector.begin(), myVector.end()); 
        for (auto& value : myVector) 
        { 
                cout << value << endl; 
        } 
        return 0; 
}



PreviousNext

Related