sort using lambda c 2b 2b

Solutions on MaxInterview for sort using lambda c 2b 2b by the best coders in the world

showing results for - "sort using lambda c 2b 2b"
Alessandra
18 Oct 2017
1vector<int> v = {50, -10, 20, -30};
2
3sort(v.begin(), v.end());  // the default sort
4// now v should be { -30, -10, 20, 50 }
5
6// sort by absolute value:
7sort(v.begin(), v.end(), [](int a, int b) { return abs(a)<abs(b); });
8// now v should be { -10, 20, -30, 50 }