递归 - hanoi
1 var hanoi = function(disc, src, aux, dst) { 2 if (disc > 0) { 3 hanoi(disc - 1, src, dst, aux); 4 document.writeln('Move disc ' + disc + ' from ' + src + ' to ' + dst + '<br/>'); 5 hanoi(disc - 1, aux, src, dst); 6 } 7 }; 8 hanoi(3, 'Src', 'Aux', 'Dst');
典型递归