结构体sort多功能排序

时间:2021-04-12 11:39:49   收藏:0   阅读:0
#include<iostream>
#include<algorithm>//sort头文件 
using namespace std;
struct student{
    int theta;//阈值
    int result;//结果
};
bool compare(student a,student b)
{//如果阈值升序排序,对于阈值相同的 按结果降序排序 
    if(a.theta==b.theta)
        return a.result>b.result;
    return a.theta<b.theta;
} 
int main(){
    int n=5
    student s[n];
    sort(s,s+n,compare);//对结构体数组进行排序,以compare方式排序 
    return 0;
}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!