//打印数组元素
void printfArray(int a[], int num) {
for (int i = 0; i < num; ++i) {
printf("%d", a[i]);
}
printf("\n");
}
//数组元素交换
void swap(int a[], int i, int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
//参数列表:数组 全排列的起始下标 结束下标 数组元素个数
void full_Permutation(int a[], int startIndex, int endIndex, int num) {
if (startIndex == endIndex) {
printfArray(a, num);
} else {
for (int i = startIndex; i <= endIndex; ++i) {
swap(a, startIndex, i);
full_Permutation(a, startIndex + 1, endIndex, num);
swap(a, startIndex, i);
}
}
}
//参数列表:数组 数组元素个数
void fullPermutation(int a[], int num) {
full_Permutation(a, 0, num - 1, num);
}
//调用示例
int main() {
int a[] = {1, 2, 3};
fullPermutation(a, 3);
return 0;
}
网友评论