c++之升序和降序排序


1.头文件

#include <functional>

2. 降序

// 期末成绩
int score[] = {99, 77, 30, 80};

// 1. 降序排列
std::sort(std::begin(score), std::end(score), greater<int>());
std::for_each(std::begin(score), std::end(score), [](const int& item) {std::cout << item << " "; });

3.降序结果

4.升序

// 期末成绩
int score[] = {99, 77, 30, 80};

// 1. 升序排列
std::sort(std::begin(score), std::end(score), less<int>());
std::for_each(std::begin(score), std::end(score), [](const int& item) {std::cout << item << " "; });

5.升序结果


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM