C++ examples for STL Algorithm:sort
Sorting Arrays and Vectors using std::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 []) { //w w w. ja va2 s.c om using MyVector = vector<int>; MyVector myVector = { 0, 1, 2, 3, 4 }; 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; }