- #include <stdio.h>
- void swap(int *a, int *b)
- {
- int temp = 0;
- temp = *a;
- *a = *b;
- *b = temp;
- return;
- }
- void permutation(int a[], int num, int total)
- {
- int i = 0;
- if (num == 0) {
- for (i = 0; i < total; i++)
- printf("%d ", a[i]);
- printf("\\n");
- }
- for (i = num-1; i >= 0; i--) {
- swap(&a[i], &a[num-1]);
- permutation(a, num-1, total);
- swap(&a[i], &a[num-1]);
- }
- }
- int main(void)
- {
- int a[] = {1, 2, 234, 5, 23, 3, 66 ,234};
- //int a[] = {1, 2, 3};
- permutation(a, sizeof(a)/sizeof(a[0]), sizeof(a)/sizeof(a[0]));
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/270320149165.html
来源: http://www.codesnippet.cn/detail/270320149165.html