头文件:
#include<algorithm>
next_permutation
例子:
#include<algorithm>
#include<stdio.h>
using namespace std;
int main()
{
int a[4]={1,2,3,4};
do{
for(int i=0;i<4;++i)
printf("%d",a[i]);
printf("\n");
}while(next_permutation(a,a+4));
return 0;
}
输出:
1234
1243
1324
1342
1423
1432
2134
2143
2314
2341
2413
2431
3124
3142
3214
3241
3412
3421
4123
4132
4213
4231
4312
4321
另一个为prev_permutation