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);
}
}
}
558 則留言
Scottemips
cialis cheap: TadalAccess – where to get generic cialis without prescription
JosephSom
where can i buy cialis online TadalAccess cialis soft
LorenMep
cheap cialis 5mg: TadalAccess – order cialis from canada
LorenMep
cialis before and after photos: cialis before and after pictures – what is cialis used for
LorenMep
mantra 10 tadalafil tablets: TadalAccess – cialis 100mg review