Hanoi(汉诺塔)问题

#include<stdio.h>
int main()
{
    //函数声明
    void hanoi(int n,char one,char two,char three);
    int m;
    printf("input the number of disks:");
    scanf("%d",&m);
    hanoi(m,‘A’,'B','C');
}
//将n个盘子从one,移动到three,借助two.
void hanoi(int n,char one,char two,char three)
{
    void move(char x,char y);
    if(n==1)
        move(one,there);
    else
    {
        hanoi(n-1,one,three,two);
        move(one,three);
        hanoi(n-1,two,one,three);
    }       
}
void move(char x,char y)
{
    printf("%c->%c\n",x,y);
}
    原文作者: 汉诺塔问题
    原文地址: https://blog.csdn.net/wmjCode/article/details/49787003
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞