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);
- Library is
<algorithm>
- Requires begin and end iterator.
- For array:
sort
(arr_head, arr_head+length). - For reverse, pass the functor
greater<int>
, i.e greater is okay. Decreasing order. - 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.
- Sorting automatically calls the function and passes the elements(by value or reference).
- We just need to pass in the name or lamda.
- [ captures ] (parameters) -> returnTypesDeclaration { lambdaStatements; }