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