C:遞迴 permutation — 排列組合
學到什麼
- 了解遞迴 (Recursion) 程式的運作。
- 利用遞迴方式實作排列組合 (permutation )。
- 藉由手寫遞迴的過程,來更深刻理解遞迴的機制,以及如何呼叫自身程式。
- 使用 C 語言來完成遞迴式排列組合的副程式,也了解如何將類似問題,用同一種程式重複執行,並設上終止條件來結束程式。
程式碼
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);
}
}
}
538 則留言
LorenzoBef
verified Modafinil vendors doctor-reviewed advice modafinil legality
Albertobub
order Cialis online no prescription: affordable ED medication – cheap Cialis online
Albertobub
discreet shipping: generic sildenafil 100mg – discreet shipping
Robertrhigo
secure checkout Viagra: legit Viagra online – legit Viagra online
JeremyPat
generic tadalafil: reliable online pharmacy Cialis – generic tadalafil