#include "iostream"
#include "vector"
#include "algorithm"
using namespace std;
struct C
{
int v;
// 从小到大排
bool operator < (const struct C &c) const
{
return v < c.v;
}
};
struct D
{
int v;
// 从大到小排
bool operator < (const struct D &d) const
{
return v > d.v;
}
};
int main()
{
int i;
struct C c[10];
for(i=0; i<10; i++)
c[i].v = i;
sort(c, c+10);
for(i=0; i<10; i++)
cout << c[i].v << " ";
cout << endl;
struct D d[10];
for(i=0; i<10; i++)
d[i].v = i;
sort(d, d+10);
for(i=0; i<10; i++)
cout << d[i].v << " ";
cout << endl;
return 0;
}
STL---排序
最新推荐文章于 2024-07-29 13:41:13 发布