#include <stdio.h>
void print(const int *v, const int size)
{
if (v != 0) {
int i;
for(i = 0; i < size; i++) {
printf("%d", v[i] );
}
printf("\n");
}
void visit(int *Value, int N, int k)
{
static level = -1;
int i;
level = level+1; Value[k] = level;
if (level == N)
print(Value, N);
else
for(i = 0; i < N; i++)
if (Value[i] == 0)
visit(Value, N, i);
level = level-1; Value[k] = 0;
}
main()
{
const int N = 4;
int Value[N];
int i;
for (i = 0; i < N; i++)
{
Value[i] = 0;
}
visit(Value, N, 0);
}
Output:-
1234
1243
1324
1423
1342
1432
2134
2143
3124
4123
3142
4132
2314
2413
3214
4213
3412
4312
2341
2431
3241
4231
3421
4321
0 comments :