C++ sort()
Sorts Arrays and Vectors
#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 []) { /*w w w . j a v a2s.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; }