【数据结构】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();

}

 

你可能感兴趣的:(数据结构)