sort()排序结构体,从大到小

来源:互联网 发布:星际公民2.6.3优化 编辑:程序博客网 时间:2024/06/07 02:51
#include<iostream>
using namespace std;
#include<algorithm>


class point
{
public:
point() :x(0),y(0){};
int x;
int y;
};
bool cmp(point a, point b)
{
return a.x > b.x;
}
int main()
{
point tmpa[2];
tmpa[0].x = 1; tmpa[0].y = 2;
tmpa[1].x = 3; tmpa[1].y = 2;
sort(tmpa, tmpa + 2,cmp);
//cout << a[0] << a[1] << a[2] << endl;
cout << tmpa[0].x << " " << tmpa[0].y << endl;
return 1;
}
0 0