Recursive Function
1. Recursive Function
再帰関数は、直接または間接的に自分を呼び出す関数です.
画像の関数は、所与の値xが0になるまで1を減算するたびに、自分で繰り返し呼び出されます.
これを使った事例では工場(継承)、ハノイタワーなどが有名です.
2. Towers of Hanoi
再帰関数を使用して解く有名なケースの1つ
function tower(n, sourcePole, destinationPole, auxiliaryPole){
if(0 == n) return;
tower(n - 1, sourcePole, auxiliaryPole, destinationPole);
document.write("Move the disk " + n + " from " +
sourcePole + n + " to " + destinationPole + "<br>");
tower(n - 1, auxiliaryPole, destinationPole,
sourcePole);
}
tower(3, 'S', 'D', 'A');
// This code is contributed by Manoj
参考資料Reference
この問題について(Recursive Function), 我々は、より多くの情報をここで見つけました https://velog.io/@ssjjyy/Recursive-Functionテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol