/*
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* 作 者: 刘同宾
* 完成日期:2012 年 11 月 24 日
* 版 本 号: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)
{
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;
}