C++ examples for STL Algorithm:sort
Sort the data into a custom order Using a predicate with sort
#include <algorithm> #include <iostream> #include <vector> using namespace std; bool IsGreater(int left, int right) { return left > right; } int main(int argc, char* argv[]) { vector<int> myVector{ 10, 6, 4, 7, 8, 3, 9 }; sort(myVector.begin(), myVector.end(), IsGreater); for (auto&& element : myVector) {//from w w w.j ava2s .com cout << element << ", "; } return 0; }