【数据结构】hanoi

#include<stdio.h>

void hanoi(int n,char x,char y,char z)
{
    static int c = 0;
    if(n==1)
        printf("%d. Move disk %d form %c to %c\n", ++c,n,x,z);
    else
    {
        hanoi(n-1,x,z,y);
        printf("%d. Move disk %d form %c to %c\n", ++c,n,x,z);
        hanoi(n-1,y,x,z);
    }
}

void main()
{
    hanoi(8,'A','B','C');
    getchar();
}

 

posted @ 2014-03-25 21:21  匡子语  阅读(285)  评论(0编辑  收藏  举报