打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
汉诺塔
userphoto

2011.01.11

关注
#include <stdio.h>

//移动步骤计数
static int number = 0;

/*
* 借助于x,从from移动n个到to
*
* n 要移动的个数
* from 初始的位置
* to 移动之后的文件
* x 需要借助的位置
*/
void hanluota(int n, char from, char to, char x)
{
if(n <= 1)
{
printf("%d : %c --> %c\n", number++, from, to);
return;
}

//把from上的n-1个移动到x暂存
hanluota(n-1, from, x, to);
//把from最下面的一个移动到to
printf("%d : %c --> %c\n", number++, from, to);
//把x上的n-1个移动到to
hanluota(n-1, x, to, from);
}

int main(void)
{
hanluota(3, 'a', 'b', 'c');
printf("finished");
getchar();
return 0;
}


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
用union取int的高、低字节
单链表的建立(C语言完整程序)
进制转换
移动字符串
C语言将4个16进制char字符合并成一个int数
《C语言程序设计》第三版课后答案
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服