2019独角兽企业重金招聘Python工程师标准>>>
1、全排列 的N中实现 [从小到大输出排列]
#include
const int _n= 20;
int _flag[20] = {0},A[20],n;
int perm(int index);
int main()
{scanf("%d",&n);perm(1);return 0;
}
int perm(int index)
{int i;if(index > n){for(i = 1; i <= n; i++)printf("%d ",A[i]);printf("
");return 0;}for(i = 1; i <= n; i++){if(_flag[i] == 0){A[index] = i;_flag[i] = 1;perm(index + 1);_flag[i] = 0;}}return 0;
}