hanoi 具体行递归

来源:互联网 发布:十字军之王优化 编辑:程序博客网 时间:2024/04/28 20:45
#include<stdio.h>
void move(char x,char y)
{
    printf("%c-->%c\n",x,y);
}
void  hanoi(int n,char one, char two,char three)
{


    if(n==1)
        move(one,three);
    else
        {
            hanoi(n-1,one,three,two);
            move(one,three);
            hanoi(n-1,two,one,three);
        }
}
int main()
{
    int m,n;
    scanf("%d",&m);
    while(m--)
    {
        scanf("%d",&n);
        hanoi(n,'A','B','C');
    }
    return 0;
}
原创粉丝点击