-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpn-alg2.c
More file actions
44 lines (37 loc) · 704 Bytes
/
pn-alg2.c
File metadata and controls
44 lines (37 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
void print_array(int *a, int n)
{
int i = 0;
for (; i < n ; i++)
{
printf("%d ", a[i]);
}
printf("\n");
}
void gen(int *a, int size, int pos)
{
if (0 == pos)
print_array(a, size);
else {
int i = 0;
for (; i <= pos; i++)
{
int tmp = a[i];
a[i] = a[pos];
a[pos] = tmp;
gen(a,size, pos -1);
tmp = a[i];
a[i] = a[pos];
a[pos] = tmp;
}
}
}
int main(int ac, char *av[])
{
int a[] = {0,1,2,3,4,5,6,7,8,9};
int count = sizeof(a)/ sizeof(a[0]);
gen(a, count, count - 1);
return 0;
}