#include<iostream>
#include<vector>
#include<algorithm>
//#include<cmath>
//#include<ctime>
//#include<numeric>
#include<string>
using namespace std;
// 字符串长度从小到大排序
bool isShorter(const string& s1, const string& s2);
int main()
{
vector<string> words{ "hablee","yuki","yinshan"};
sort(words.begin(), words.end(), isShorter); // 传入自定义排序函数名
for (auto item : words) {
cout << item << " ";
}
cout << endl;
return 0;
}
bool isShorter(const string& s1, const string& s2)
{
return s1.size()<s2.size();
}
c++使用sort实现自定义排序
最新推荐文章于 2024-01-21 18:15:46 发布