在C++的标准函数库STL中,next_permutation()函数用于求数列的全排列。
函数原型:
template<class BidirectionalIterator>
template<class BidirectionalIterator, class BinaryPredicate>
两个重载函数,第二个带谓词参数_Comp,其中只带两个参数的版本,默认谓词函数为"小于"。
返回值:bool类型(当前数列是全排列最后一个时,返回false)
例子1(int型):
int main(){
}
输出:312/321
所以要想得到所有全排列
int a[] = {3,1,2}; 然后先排序为:a[] = {1,2,3};
例子2(string型)
int main(){
}
库中另一函数prev_permutation()与next_permutation()相反