用递归算法编n!的全排列
收起
知与谁同
2018-07-17 09:46:50
1385
0
1
条回答
写回答
取消
提交回答
-
void genPermutation(int k, int n, int* perm) {
if (k >= n) {
for (int i = 0; i < n; ++i) {
cout << perm[i] << " ";
}
cout << endl;
}
for (int i = k; i < n; ++i) {
swap(perm[i], perm[k]);
genPermutation(k + 1, n, perm);
swap(perm[i], perm[k]);
}
}
2019-07-17 22:54:54