结构体可以根据里面的数据进行排序,会调换整个结构体顺序
struct q
{
char name[20];
int num;
int score;
}x[10005];
int cmp(q x,q y)
{
if(x.num!=y.num)
return x.num>y.num;
return x.score<y.score;
}
sort(x,x+n,cmp);
struct q
{
char name[20];
int num;
int score;
}x[10005];
int cmp(q x,q y)
{
if(x.num!=y.num)
return x.num>y.num;
return x.score<y.score;
}
sort(x,x+n,cmp);
转载于:https://www.cnblogs.com/wzl19981116/p/9374693.html