结构体排序

Posted allinoo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了结构体排序相关的知识,希望对你有一定的参考价值。

struct Student 
	int s;
;
bool cmp1(Student x, Student y) 
	return x.s > y.s;   //定义降序排序(从大到小) 

bool cmp2(Student x, Student y) 
	return x.s < y.s;   //定义升序排序(从小到大) 

int main()

	Student s[50];
	//为方便,输入学生数据这一步忽略
	sort(s, s + 50, cmp1); //排序

以上是关于结构体排序的主要内容,如果未能解决你的问题,请参考以下文章