应用了递归方法
#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:";
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)
{
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;
}