greater和less的用法
来源:互联网 发布:sysbench 1.0 mysql 编辑:程序博客网 时间:2024/04/27 17:08
greater使内置类型从大到小排序,而less从小到大
注意:
sort用greater排序,则a[0]到a[n]有大到小排序。
priority_queue用greater排序,则先取出的是最小值。
#include <iostream> #include <algorithm> using namespace std; int main() { int a[5] = {4, 1, 5, 3, 2}; sort(a, a + 5, greater<int>()); //由大到小排序 for(int i = 0; i < 5; i++) cout << a[i] << " "; cout<<"\n"; sort(a, a + 5, less<int>()); //由小到大排序(sort一般默认为从小到大,所以less可以省略) for(int i = 0; i < 5; i++) cout<<a[i]<<" "; return 0;}
1 0
- greater和less的用法
- greater<int>()和less<int>()的使用
- greater<int>()和less<int>()的使用
- greater<int>()和less<int>()的使用
- greater<int>()和less<int>()的使用
- greater<int>()和less<int>()的使用
- C++ greater<int>()和less<int>()
- STL greater<T>() 和less<T>()
- greater<int>()的用法
- linux more和less的用法
- c++中的sort 排序函数 less和greater使用
- Less的常见用法
- less的一些用法整理
- less用法
- Less 用法
- history、less和.bash_profile配置文件用法一点
- Linux中more和less命令用法
- Linux中more和less命令用法
- 马踏棋盘问题
- 【angular2】(3)ng build部署后base文件路径问题
- nditer —— numpy.ndarray 多维数组的迭代
- caffe下fcn数据集的制作
- asp.net core mvc剖析:KestrelServer
- greater和less的用法
- 第一次创建svn无法commit程序的问题
- 2.18队列,栈,StarUML9种图
- 获取当前访问所用的浏览器
- CPP学习一类模版
- OpenCV中的函数waitKey()函数简介
- linux进度条功能模拟
- 【Java】接口
- C#实现删除自身程序