#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
typedef struct Test
{
public:
int n;
char* s;
}Test;
vector<Test> t;
bool intcmp(Test a,Test b)
{
return a.n < b.n;
}
bool strcmp1(Test a,Test b)
{
return strcmp(a.s,b.s) < 0;
}
int main()
{
Test tmp = {0};
tmp.n = 4;
tmp.s = "gggg";
t.push_back(tmp);
tmp.n = 1;
tmp.s = "dddd";
t.push_back(tmp);
tmp.n = 2;
tmp.s = "cccc";
t.push_back(tmp);
sort(t.begin(),t.end(),strcmp1);
for (vector<Test>::iterator iter = t.begin(); iter != t.end(); ++iter)
{
cout << iter->s << endl;
}
}
C++ Sort函数用法
最新推荐文章于 2025-03-04 10:17:10 发布