目录
- 1 基础知识
- 2 模板
- 3 工程化
1 基础知识
sort()
函数中的greater<int>()
参数表示将容器内的元素降序排列。不填此参数,默认表示升序排列。
vector<int> a = {1,2,3};
sort(a.begin(), a.end(), greater<int>()); //将a降序排列
sort(a.begin(), a.end()); //将a升序排列
2 模板
#include <iostream>
#include <algorithm>using namespace std;int main() {vector<int> a = {8,3,4,5,6};sort(a.begin(), a.end(), greater<int>());for (auto x : a) {cout << x << " ";}cout << endl;return 0;
}
上述程序输出,
8 6 5 4 3
3 工程化
暂无。。。