Given a set of n≧1 elements, the problem is to print all possible permutations of this set. For example, if the set is (1,2,3), then the set of permutations is {(1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,2,1), (3,1,2)}.
<Hint1>
Looking at the case of four elements (1,2,3,4). The answer can be constructed by writing
<Hint2>
A recursive method to implement the above idea is as follows:
Consider the case of (1,2,3,4), that is, n=4.
You will be provided with the following sample code, and asked to implement function "Swap" and "Perm.
#include <stdio.h>
char list[10];
void show(int n)
{
int i;
printf("(%c", list[0]);
for (i=1; i<n; i++) {
printf(",%c", list[i]);
}
printf(")\n");
}
void Swap(int k, int i)
{
/*your code*/
}
void Perm(int k, int n)
{
/*your code*/
}
int main(void)
{
int num, i;
scanf("%d", &num);
for(i=0; i<num; i++)
list[i] = '1'+i;
Perm(0, num);
return 0;
}
The decimal number n that represents the number of elements in the set.
(1≦n≦5)
In the output you should print all the permutations.
Be sure to add a newline character '\n' at the end of each line.