首页 > 编程语言 > 详细

C++中Vector排序

时间:2019-11-11 17:59:46      阅读:91      评论:0      收藏:0      [点我收藏+]

1.普通类型(由大到小排序)

int main()
{
    sort(v.begin(),v.end());
}

2.普通类型(由小到大排序)

bool comp(const int &a,const int &b)
{
    return a>b;
}
int main()
{
    sort(v.begin(),v.end(),comp);
}

 

3.结构体类型

struct student
{
     char name[10];
     int score;
};

bool comp(const student &a, const student &b)
{
    return a.score < b.score; //由小到大排序
}
 
int main()
{
    vector<student> vectorStudents;
    sort(vectorStudents.begin(),vectorStudents.end(),comp);
}

 

C++中Vector排序

原文:https://www.cnblogs.com/KMould/p/11836886.html

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