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);
}

你可能感兴趣的:(递归函数,hanoi,汉诺塔问题)