汉诺塔-递归实现

#include<stdio.h>
void move(char x,char y)
{
	printf("%c->%c\n",x,y);
}
//将n个盘子从1中借助2移动到3
void hanoi(int n,char one,char two,char three)
{
	if(n==1)
		move(one,three);
	else
	{
		hanoi(n-1,one,two,three);
		move(one,three);
		hanoi(n-1,two,one,three);

	}
}
int main()
{
	int m;//盘子个数
	scanf("%d",&m);
	hanoi(m,'A','B','C');
	return 0;
}

posted @ 2018-03-30 12:21  zhchoutai  阅读(125)  评论(0编辑  收藏  举报