1. Sorting #

Created Sunday 03 May 2020

std::sort(ds.begin(), ds.end())

int arr[] = {1,3,4,23,4,4};
sort(arr, arr+len);
  1. Library is <algorithm>
  2. Requires begin and end iterator.
  3. For array: sort(arr_head, arr_head+length).
  4. For reverse, pass the functor greater<int>, i.e greater is okay. Decreasing order.
  5. Sorting on the basis of some object. Custom, write a custom function. Just overload the function(). We’ll write our own comparator. Pass in a lambda.
    1. Sorting automatically calls the function and passes the elements(by value or reference).
    2. We just need to pass in the name or lamda.
    3. [ captures ] (parameters) -> returnTypesDeclaration { lambdaStatements; }