凤逆天下翼扑倒月:汉诺塔问题解答。请注析

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 15:47:30
#include <iostream>
using namespace std;
void move(char getone,char putone)
{
cout<<getone<<"-->"<<putone<<endl;
}
void hanoi(int n,char one,char two,char three)
{
void move(char getone,char putone);
if (n==1) move (one,three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
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');
}
{
void move(char getone,char putone);
if (n==1) move (one,three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
解归递推的传递步骤和每一步N的值与走向,谢

明天我给你看一下,现在要睡觉了~~