hanoi问题
来源:互联网 发布:加强网络舆情管理通知 编辑:程序博客网 时间:2024/05/15 09:09
采用递归的方法,将n-1个盘从第一座借助第三座移到第二座
将第n个盘从第一座移到第三座
将n-1个盘从第二座借助第一座移到第三座
#include<iostream>
using namespace std;int main()
{
void hanoi(int n,char one,char two,char three);
int m;
cout<<"input the number of disks:"<<endl;
cin>>m;
cout<<"the steps of moving"<<m<<"disks:"<<endl;
hanoi(m,'A','B','C');
return 0;
}
void hanoi(int n,char one,char two,char three)
//将n个盘从one座借助two座移到three
{
void move(char x,char y);
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)
{
cout<<x<<"-->"<<y<<endl;
}
0 0
- Hanoi 问题
- hanoi问题
- Hanoi问题
- Hanoi问题
- hanoi问题
- hanoi问题
- Hanoi问题
- Hanoi问题
- hanoi问题
- Hanoi问题
- Hanoi 问题
- hanoi问题
- hanoi问题
- Hanoi双塔问题(hanoi)
- Hanoi塔问题
- Hanoi塔问题(C)
- 双色Hanoi塔问题
- 双色Hanoi塔问题
- Android studio百度地图的使用
- mysql5.7.17报错:ERROR! The server quit without updating PID file
- The Overview of Rule Placement Problem in SDN(规则放置问题的概述)
- 解决Spring MVC @ResponseBody返回中文字符串乱码问题
- js,jq,css多方面实现简易Tab切换
- hanoi问题
- raspi-config command not found resolution
- 闭包(Closures)
- oracle基本命令集合(2)--单行函数
- super在对象的内部使用,代表父类对象
- 铁路修复计划(裸Kruskal+二分)
- USB无线网卡配置ICS失败,你可以连接到SoftAP,但可能无法使用internet服务
- JavaScrip 时间格式化 ----转载
- 中介者模式