std::sort

Applies to: cpp

std::sort orders a range in place in O(n log n). Pass begin/end and an optional comparator (often a lambda) to sort by a custom key or in descending order.

std::sort(v.begin(), v.end());                       // ascending
std::sort(v.begin(), v.end(), [](int a,int b){return a>b;}); // descending

See also: sorting, iterator, std-vector, lambda