C++全排列 next_permutation
全排列函数 next_permutation
这是C++的STL中专门用来排列的函数(可以自动处理存在重复数据集的排列问题)
使用时要加上头文件 #include <algorithm>
using namespace std;
函数在C++程序中的调用方法:next_permutation(start,end);
函数要求输入的是排列序列的头指针和尾指针
下面我举例说明一下这个函数的使用方法:
//全排列 数组
int a[N];
sort(a,a+N);
next_permutation(a,a+N);
//向量
vector<int>v;
sort(v.begin(),v.end());
next_permutation(v.begin(),v.end());
//在程序中使用的完整代码
vector<int>v;
sort(v.begin(),v.end());
do
{
for(int i=0;i<v.size();++i)
cout<<v[i]<<" ";
cout<<endl;
}while(next_permutation(v.begin(),v.end()));
作者:红雨
出处:https://www.cnblogs.com/52why
微信公众号: 红雨python