next_permutation函数
来源:互联网 发布:spss怎么预测未来数据 编辑:程序博客网 时间:2024/06/05 18:19
STL中的next_permutation函数
在C++的标准函数库STL中,next_permutation()函数用于求数列的全排列。
函数原型:
template<class BidirectionalIterator>
bool next_permutation(
BidirectionalIterator _First,
BidirectionalIterator _Last
);
template<class BidirectionalIterator, class BinaryPredicate>
bool next_permutation(
BidirectionalIterator _First,
BidirectionalIterator _Last,
BinaryPredicate _Comp
);
两个重载函数,第二个带谓词参数_Comp,其中只带两个参数的版本,默认谓词函数为"小于"。
返回值:bool类型(当前数列是全排列最后一个时,返回false)
例子1(int型):
int main(){
int a[] = {3,1,2};
do{
cout << a[0] << " " << a[1] << " " << a[2] << endl;
}while (next_permutation(a, a+3));
return 0;
}
输出:312/321 因为原数列不是从最小字典排列开始。
所以要想得到所有全排列
int a[] = {3,1,2}; 然后先排序为:a[] = {1,2,3};
例子2(string型)
int main(){
string str;
cin >> str;
sort(str.begin(), str.end());
do{
cout << str << endl;
}while (next_permutation(str.begin(), str.end()));
return 0;
}
库中另一函数prev_permutation()与next_permutation()相反,懂的...
- next_permutation函数
- next_permutation函数
- next_permutation()函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- next_permutation函数
- js或java前边补0操作.txt
- 使用 .NET Framework 2.0 在您的应用程序中支持证书
- 查询,删除重复数据 sql.TXT
- Xcode4如何添加Frameworks
- DES加密、解密字符串算法
- next_permutation函数
- js设置cookie js读取cookie js设置cookie时间 cookie 类
- 新学期------对于上学期的总结和新的目标
- 如何隐藏一个程序在任务栏上图标
- SVN版本回滚——反响合并
- 反汇编时的函数识别及各函数调用约定的汇编代码分析
- 数值范围
- 查询水货mb525+,mb526和mb525出产地,销售地,是否翻新机,希望帮得到你们
- 呼叫中心mvb事件方法总结草稿