/*
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* 作 者:张浩
* 完成日期:2012 年11月22日
* 版 本 号:v1.0
* 输入描述: 移动汉诺塔
* 问题描述: 略
* 程序输出: 移动每一个盘子的步骤
* 问题分析: 利用递推思想
* 算法设计: 略
*/
#include<iostream>
using namespace std;
int main()
{
void hanoi(int n,char one,char two,char three);
int m;
cout<<"请输入需要移动盘子的个数:";
cin>>m;
cout<<"移动"<<m<<"个盘子的步骤是:"<<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;
}
运行结果:
心得体会:我得好好看看书了。。。。。
821

被折叠的 条评论
为什么被折叠?



