首页 > 编程语言 > 详细

结构体sort多功能排序

时间:2021-04-10 15:35:26      阅读:26      评论: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;
}

 

结构体sort多功能排序

原文:https://www.cnblogs.com/liyou555/p/14640495.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!