_在路上

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#include <stdio.h>

/*
***********************************************************************/ /* 汉诺塔: 将n个盘从one座借助two座,移到three座 */ /************************************************************************/ void hanoi_Example (void) { int m; printf("input the number of diskes:"); scanf("%d",&m); printf("The step to move %d diskes:\n",m); hanoi(m,'A','B','C'); } void hanoi(int n,char one,char two,char three) { 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); }

int main ()
{
hanoi_Example();

  return 0;
}
posted on 2012-10-04 21:12  _在路上  阅读(231)  评论(7编辑  收藏  举报