next_permutation(begin,end)
next_permutation(begin,end)
当排列还存在下一种(以字典序排列)排法时,返回true
,否则返回false
返回true
的同时,把数组变成字典序中的下一种排法。
测试代码:
// Created by CAD on 2020/1/15.
#include <bits/stdc++.h>
#include <ext/rope>
using namespace std;
int main()
{
int a[4]={1,2,3};
do{
for(int i=0;i<=2;++i)
cout<<a[i]<<" ";cout<<endl;
}while(next_permutation(a,a+3));
return 0;
}
输出:
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
CAD加油!欢迎跟我一起讨论学习算法,QQ:1401650042