Hanoi问题

#include<stdio.h>
int main()
{
  int m;
  void hanoi(int n,char x,char y,char z);
  printf("input the number of disk:\n");
  scanf("%d",&m);
  hanoi(m,'A','B','C');
  return 0;
}
void hanoi(int n,char x,char y,char z)
{
  void move(char a,char b);
  if(n==1)
  move(x,z);
  else
  {
  hanoi(n-1,x,z,y);
  move(x,z);
  hanoi(n-1,y,x,z);
  }
}
void move(char a,char b)
{
  printf("%c----->%c\n",a,b);
}

posted @ 2016-03-09 16:53  胡卫雄  阅读(302)  评论(0编辑  收藏  举报