<html>
<body>
<script type="text/javascript">
document.write("汉诺塔</br>")
function hanoi(n,A,B,C) {
if(n==1) {
document.write("把1号盘子从" A "移到" C "</br>");
count ;
}
else {
hanoi(n-1,A,C,B);
document.write("把" n "号盘子从" A "移到" C "</br>");
count ;
hanoi(n-1,B,A,C);
}
}
var count=0;
var n=4;
var A="A";
var B="B";
var C="C";
hanoi(n,A,B,C);
document.write("共 " count " 次</br>");
</script>
</body>
</html>
Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved