next_permutation,pre_permutation,random_shuffle
来源:互联网 发布:华为大数据在贵州 编辑:程序博客网 时间:2024/06/05 23:43
直接代码:
//next_permutation prev_permutation#include<iostream>#include<string>#include<vector>#include<algorithm>#include<functional>using namespace std;int main(){int a[]={1,2,3};vector<int>v(a,a+3);copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));cout<<endl;while(next_permutation(v.begin(),v.end())){copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));cout<<endl;}//调用了next_permutation之后cout<<"after next_permutation:"<<endl;copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));cout<<endl;cout<<"***********************"<<endl;while(prev_permutation(v.begin(),v.end())){copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));cout<<endl;}cout<<"after prev_permutation:"<<endl;copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));cout<<endl;while(prev_permutation(v.begin(),v.end())){copy(v.begin(),v.end(),ostream_iterator<int>(cout," "));cout<<endl;}system("pause");return 0;}
//重排元素#include<iostream>#include<string>#include<vector>#include<algorithm>#include<functional>#include<ctime>using namespace std;class MyRandom{public:ptrdiff_t operator()(ptrdiff_t max){//RAND_MAX是一个常量32767double temp;temp=static_cast<double>(rand())/static_cast<double>(RAND_MAX);return static_cast<ptrdiff_t>(temp*max);}};int main(){int a[]={1,2,3,4,5,6,7,8,9,10};vector<int>v(a,a+10);vector<int>vv(a,a+10);random_shuffle(v.begin(),v.end());//只能一次,以后都是这个排序for(vector<int>::iterator iter=v.begin();iter!=v.end();++iter){cout<<*iter<<" ";}cout<<endl;srand(unsigned(time(NULL)));MyRandom suiji;random_shuffle(vv.begin(),vv.end(),suiji);//现在实现了真正的随机for(vector<int>::iterator it=vv.begin();it!=vv.end();++it){cout<<*it<<" ";}cout<<endl;system("pause");return 0;}
- next_permutation,pre_permutation,random_shuffle
- C++标准库中next_permutation和pre_permutation实现原理
- STL快速全排列函数next_permutation与pre_permutation
- 九、STL算法-变序算法(random_shuffle、reverse、next_permutation)
- 求下一个排列组合和前一个排列组合(next_permutation和pre_permutation)
- random_shuffle
- random_shuffle
- random_shuffle
- random_shuffle()
- random_shuffle
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- 远程调用Excel、Word、PowerPoint,服务器端设置
- Start learning Android
- reverse,reverse_copy,rotate,rotate_copy
- 学生信息管理系统————布尔值
- APUE读书笔记 6--------- 系统数据文件和信息
- next_permutation,pre_permutation,random_shuffle
- 黑马程序员--C#线程
- 进程间通信之(一)剪贴板
- partition,stable_partition,sort,stable_sort
- 依赖倒置原则--针对接口编程
- partial_sort,partial_sort_copy,nth_element
- jsp页面导出成word文件
- Lisp的作用域和生存期(scope and extent in lisp)
- oracle存储过程异常信息的显示