如n==3时的全排列为
123
132
213
231
312
321
代码如下:
#include<iostream>
#include<algorithm>
using namespace std;
扫描二维码关注公众号,回复:
9420177 查看本文章
int main(){
int a[10] = { 1,2,3};
//a[0]~a[2]之间的序列需要求解next_permutation
do{
cout<<a[0]<<a[1]<<a[2]<<endl;
}while(next_permutation(a,a+3)); //当前为最后一个全排列时返回为0
//此时若再调用next_permutation,a[0]~a[2]将变回初试模样
}
输出结果为:
123
132
213
231
312
321