//"汉诺塔"求寻常解 举例圆盘数量为3
var hanoi=function(disc,src,aux,dst){
if(disc>0){
hanoi(disc-1,src,dst,aux);
document.writeln('move disc'+disc+'from'+src+'to'+dst);
hanoi(disc-1,aux,src,dst);
}
}
hanoi(3,'Src','Aux','Dst');
//结果
move disc 1 from Src to Dst
move disc 2 from Src to Aux
move disc 1 from Dst to Aux
move disc 3 from Src to Dst
move disc 1 from Aux to Src
move disc 2 from Aux to Dst
move disc 1 from Src to Dst
汉诺塔 递归求解
最新推荐文章于 2020-10-26 12:39:17 发布