<algorithm>中的sort()函数
来源:互联网 发布:服务器如何开放端口 编辑:程序博客网 时间:2024/06/08 16:16
迭代器iterator
begin()返回一个iterator 它指向容器的第一个元素
end()返回一个iterator 它指向容器的末元素的下一个位置
sort函数:前两个参数是两个指针(记为分别指向元素a和元素b),最后一个参数是一个比较函数,默认比较函数返回值为真时,将a到b之间的数从小到大排列;前两个参数为[a,b),即包含元素a,不包含元素b
#include <iostream>#include <algorithm>#include <vector>using namespace std;#define ElemType intbool less_than(ElemType a, ElemType b) { return a > b;}int main() { vector<ElemType> A; ElemType B[20]; for (int i = 0; i < 20; i++) { A.push_back(i); B[i] = i; } sort(A.begin(), A.end(), less_than); sort(B, B + 20, less_than); vector<ElemType>::iterator it; for (it = A.begin(); it != A.end(); it++) { cout << (*it) << " "; } cout << endl; for (int i = 0; i < 20; i++) { cout << B[i]<<" "; } cout << endl; return 0;}
阅读全文
0 0
- <algorithm>中的sort()函数
- Algorithm头文件中的sort函数使用
- algorithm中sort函数
- 用<algorithm>头文件中的sort函数排序
- algorithm的sort排序函数
- #include<algorithm>中的sort算法
- algorithm中的next_permutation函数
- algorithm中sort函数的使用
- sort algorithm
- sort algorithm
- Sort algorithm
- Sort Algorithm-->Bubble Sort
- Sort Algorithm-->Select Sort
- [C++]Algorithm中的函数简介
- c++中的sort 函数
- matlab中的sort函数
- C++中的sort函数
- matlab中的sort函数 .
- 设计模式学习—传输对象模式(Transfer Object Design Pattern)
- 用Eclipse插件Git,让Repository回滚到之前的版本
- JAVAEE之Servlet进阶
- http://repo.varnish-cache.org/redhat/varnish-3.0/el7/x86_64/repodata/repomd.xml: [Errno 14]
- Java国际化
- <algorithm>中的sort()函数
- 卸载事件off()方法
- Nmap扫描教程之基础扫描详解
- ANDROID下使用PROPERTIES文件保存程序设置
- Activity之间传递数据的三种方式详解
- 深入浅出,Handler机制外科手术式的剖析(ThreadLocal,Looper,MessageQueen,Message)(上)
- ViewPagerIndicator
- Angular初体验
- 06. 会话管理