hanoi(漢諾)塔問題

#include<stdio.h>
int main()
{
    void hanoi(int n,char one,char two,char three);
    int m;
    scanf("%d",&m);
    printf("移動%d個盤子\n",m);
    hanoi(m,'A','B','C');
}
void hanoi(int n,char one,char two,char three)
{
    void move(char x,char y);
    if(n==1)
        move(one,three);
    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);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章