牛哄哄的 汉诺塔递归

#include <stdio.h>


void move (int num, char f, char t)
{
    printf("%d : %c -> %c\n", num, f, t);
}


void hanoi(int num, char one, char two, char three)
{
    if(num == 1)
        move(num, one, three);
    else { 

   hanoi(num-1, one, three, two);
        move(num, one, three);
        hanoi(num-1, two, one, three);

 }
}


int main(int argc, char *argv[])
{
    int num = 3;
    hanoi(num, 'a', 'b', 'c');
    return 0;
}

 

posted @ 2015-02-12 12:51  chencesc  阅读(128)  评论(0编辑  收藏  举报