首页 > 其他 > 详细

牛哄哄的 汉诺塔递归

时间:2015-02-12 13:51:40      阅读:277      评论:0      收藏:0      [点我收藏+]
#include <stdio.h>


void move (int num, char f, char t)
{
    printf("%d : %c -> %c\n", num, f, t);
}


void hanoi(int num, char one, char two, char three)
{
    if(num == 1)
        move(num, one, three);
    else { 

   hanoi(num-1, one, three, two);
        move(num, one, three);
        hanoi(num-1, two, one, three);

 }
}


int main(int argc, char *argv[])
{
    int num = 3;
    hanoi(num, a, b, c);
    return 0;
}

 

牛哄哄的 汉诺塔递归

原文:http://www.cnblogs.com/chencesc/p/4287758.html

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