We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7447e71 commit a205014Copy full SHA for a205014
sort_lambda.cpp
@@ -7,6 +7,7 @@
7
int main(){
8
std::vector<std::string> myvec;
9
myvec = {"apple", "lemon", "orange", "banana", "onion", "melon", "durian"};
10
+ //first sort by length(the longer the former), then by lexicographical order
11
std::sort(myvec.begin(), myvec.end(),
12
[](const std::string& a, const std::string& b) -> bool{return a.size() == b.size() ? a < b : a.size() > b.size();});
13
std::copy(myvec.begin(), myvec.end(), std::ostream_iterator<std::string>(std::cout, " "));
0 commit comments