网上关于sort结构体排序都不完整,我来写一个完整版的 2014-08-09 16:50 60人阅读 评论(0) 收藏

主要参考sort函数_百度文库, 但是那篇有错误


2.结构体排序,a升,b降,c降

01 #include <iostream>
02 #include <algorithm>
03 using namespace std;
04 struct data
05 {
06  int a;
07  int b;
08  int c;
09 };
10 bool cmp(data x,data y)
11 {
12  if(x.a!=y.a) return x.a<x.y;
13  if(x.b!=y.b) return x.b>y.b;
14  if(x.c!=y.c) return x.c>y.c;
15 }
16 int main()
17 {
18  .....
19  sort(array,array+n,cmp);
20  return 0;
21 }

版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/wmxl/p/4662722.html