struct Nodes
{
int x, y;
};
Nodes nd[MAX_N];
int main(void){
......
//按照y升序 x降序排列
sort(nd, nd+ n,
[](Nodes & n1, Nodes & n2)
{
return n1.y == n2.y ? n1.x > n2.x : n1.y < n2.y;
});
}
或直接
struct node{
int x, y;
node(int x, int y):x(x), y(y){}
node(){}
bool operator<(const node& n) const{
return this->y == n.y ? this->x > n.x : this->y < n.y;
}
};