泛型算法sort,fill,fill—n,stable—sort,accumulate
来源:互联网 发布:c 键值对数组 编辑:程序博客网 时间:2024/06/06 05:18
#include <iostream>#include <vector>#include<string>#include<algorithm>#include<numeric>using namespace std;bool abdede(const int &i,const int &j){return i>j;}int main(){ vector<int> a; a.push_back(2); a.push_back(1); a.push_back(3); a.push_back(2); a.push_back(4); a.push_back(3);//搜索到具体的内容,只能采用到顺序搜索 vector<int>::iterator i=find(a.begin(),a.end(),1); //代替了for循环 if(i==a.end()) { cout<<"没有发现"<<endl;return 0; }cout<<*i<<endl; sort(a.begin(),a.end());//从小到大排序,for(int j=0;j<a.size();j++)cout<<a[j]<<endl;a.erase(unique(a.begin(),a.end()),a.end());stable_sort(a.begin(),a.end(),abdede);//从大到小排序,for( j=0;j<a.size();j++)cout<<a[j]<<endl;reverse(a.begin(),a.end());//倒序for( j=0;j<a.size();j++)cout<<a[j]<<endl; fill(a.begin(),a.end(),4);//把每一个都填4int sum=accumulate(a.begin(),a.end(),10);//sum=所以和cout<<sum<<endl;vector<int> v;fill_n(back_inserter(v),10,1);for( j=0;j<v.size();j++)cout<<v[j]<<endl;return 0;}
0 0
- 泛型算法sort,fill,fill—n,stable—sort,accumulate
- 泛型算法(find、count、sort、fill、unique、copy、lambda、迭代器)
- Arrays类中sort,binarySearch,fill实例
- 泛型算法系列12:fill()&&fill_n()
- STL算法find,find_if,find_if_not,sort,fill,for_each,count,adjacent_find,random_shuffle,prev_permutation
- Uva10603——Fill
- fill ()
- fill
- Fill
- fill
- 泛型算法之——fill fill_n back_inserter copy replace replace_copy
- arrays.sort用法arrays.fill用法arrays.equals用法
- (77)Collections类:sort、max、binarySearch、fill、replaceAll、reverse
- 泛型算法——quick sort
- 【C++】泛型算法里的fill()函数用法
- 泛洪填充算法(Flood Fill Algorithm)
- 【STL】算法 — sort
- counting sort(stable)
- Hadoop虚拟机固定Ip上网
- hdu 3038 How Many Answers Are Wrong
- C++异常处理学习记录
- ORACLE 定时执行存储过程<一>
- 抽象类
- 泛型算法sort,fill,fill—n,stable—sort,accumulate
- ;学习路线
- STM32F4 定时器TIM1输出七路PWM信号【使用库函数
- 黑马程序员——第九天(集合框架)
- caffe使用MemoryDataLayer从内存中加载数据
- vps centos 搭建vpn服务pptpd
- iOS保存数据——数据存取(3)
- 计算机视觉顶级期刊
- Unix & Linux 命令分类表