汉诺塔小程序

#include <stdio.h>

 

typedef enum { first=1, second, third } Stack;

 

void hannoi (Stack from, Stack to, unsigned int n)

{

if (n == 1)

printf ("%d-->%d\n",from, to);

else

{

/* 6-from-to表示除了源柱子和目的柱子的另一根柱子 */

hannoi (from, 6-from-to, n-1);

hannoi (from, to, 1);

hannoi (6-from-to, to, n-1);

}

}

 

int main ()

{

hannoi (first, third, 3);

 

return 0;

}

posted @ 2011-08-08 07:43  jialejiahi  阅读(273)  评论(0编辑  收藏  举报