首页 > 其他 > 详细

汉诺塔matlab实现

时间:2015-10-06 19:30:27      阅读:326      评论:0      收藏:0      [点我收藏+]

Matlab的递归调用,好久不用matlab了,练练手。

 

global handCount;

handCount = 1;

huuotsun(1, 2, 3, 3)

 

 

function huuotsun(cur, buf, tar, num)

    global handCount;

    if num == 1

        str = sprintf(‘c %d plate  %d to %d ‘, handCount, cur, tar);

        disp(str);

        handCount = handCount + 1;

    else

        huuotsun(cur, tar,buf, num -1);

        str = sprintf(‘c %d plate  %d to %d ‘, handCount, cur, tar);

        disp(str);

        handCount = handCount + 1;

        huuotsun(buf, cur,tar, num -1);

    end

end

 

 

汉诺塔matlab实现

原文:http://www.cnblogs.com/guopengfei/p/4857480.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!