直接看代码即可,对于lambda部分的解释:a,b基本算作两个抽象的比较对象,每次会比较这两个,返回true:表示a应该排在b前面(a<b),返回false:表示b应该排在a前面(a>b),具体可查看cpprefernece
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> /* sort*/
#include <functional> /*std::greater<int>()*/int main() {std::vector<int> values = { 3,5,6,3,2 };std::sort(values.begin(), values.end());/*正序*/std::sort(values.begin(), values.end(), std::greater<int>());/*反序*/std::sort(values.begin(), values.end(), [](int a, int b) {return a < b;});for ( int value : values) {std::cout << value << std::endl;}
}