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);
}
}
}
547 則留言
LorenMep
canadian no prescription pharmacy cialis: TadalAccess – tadalafil troche reviews
Scottemips
tadalafil liquid review: TadalAccess – cialis for sale online
Scottemips
cialis for sale over the counter: TadalAccess – tadalafil generic reviews
Frankiemef
https://tadalaccess.com/# cialis for daily use reviews
Frankiemef
https://tadalaccess.com/# cialis vs.levitra