使用递归函数解决PHP中的汉诺塔问题
-
使用递归函数解决PHP中的汉诺塔问题
function hanoi($n, $start, $end, $temp) {if ($n === 1) {echo “Move disk 1 from $start to $end\n”;} else {hanoi($n – 1, $start, $temp, $end);echo “Move disk $n from $start to $end\n”;hanoi($n – 1, $tem
function hanoi($n, $start, $end, $temp) {if ($n === 1) {echo “Move disk 1 from $start to $end\n”;} else {hanoi($n – 1, $start, $temp, $end);echo “Move disk $n from $start to $end\n”;hanoi($n – 1, $tem