2021-12-11 C++的vector<string>按字符长度排序

Lambda 表达式排序

// 从小到大排序
sort(records.begin(), records.end(), [](string a, string b){
	return a.length() < b.length();
});

自定义静态函数

static bool cmp(string a, string b){
    return a.length() < b.length();
}
sort(records.begin(), records.end(), cmp);

你可能感兴趣的:(C++日常笔记,c++,排序算法,leetcode)