Perl 脚本之2:汉诺塔相关脚本
发布时间:2020-12-15 23:57:32 所属栏目:大数据 来源:网络整理
导读:????紧跟之前的脚本,这个也是一个关于递归方面比较有名的算法:汉诺塔 ???? #!/usr/bin/perl#author:?peipei#date:2014_06_06sub?hanoi{????my?($n,$start,$end,$extra)=@_;????if?($n?==?1){????????????print?"Move?disk?#1?form?$start?to?$end.?n?";??
????紧跟之前的脚本,这个也是一个关于递归方面比较有名的算法:汉诺塔 ???? #!/usr/bin/perl #author:?peipei #date:2014_06_06 sub?hanoi{ ????my?($n,$start,$end,$extra)=@_; ????if?($n?==?1){ ????????????print?"Move?disk?#1?form?$start?to?$end.?n?"; ????}???else?{ ????????????hanoi($n-1,$extra,$end); ????????????print?"Move?disk?#$n?from?$start?to?$extra.?n"; ????????????hanoi($n-1,$extra,$start); ????} } ???? ????hanoi(5,A,B,C); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |