码迷,mamicode.com
首页 > 其他好文 > 详细

汉诺塔-递归实现

时间:2015-07-06 21:46:33      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

#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;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

汉诺塔-递归实现

标签:

原文地址:http://blog.csdn.net/u012701023/article/details/46778483

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!