C:遞迴 permutation -- 排列組合
程式碼
list = [a, b, c];
perm(list, 0, n-1);
void perm ()
{
int j, temp;
if (i == n)
{
for (j=0; j<=n; j++)
{
printf("%c", list[j]);
}
printf(" ");
}
else
{
for (j=0; j<=n; j++)
{
swap(list[i], list[j], temp);
perm(list[i], i+1, n);
swap(list[i], list[j], temp);
}
}
}
留言
張貼留言