指教一下才c++ 的汉诺塔问题

来源:百度知道 编辑:UC知道 时间:2024/06/09 02:45:33
源程序如下:
#include <iostresm>
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,charputone);
if(n==1) move(one,three);
else
{hanoi(n-1,one,there,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<<"enter the numberof diskes:";
cin>>m;
cout<<"the steps tomocing"<<m<<"diskes:"<<endl;
hanoi(m,'A','B','C');
}

运行后:
enter the number of diskes:3
the steps to moving 3 diskes:
A-->C
A-->B
C-->B
A-->C
B-->A
B-->C
A-->C

这个回归小弟我实在搞不懂
{hanoi(n-1,one,there,two);
move(one,three);
hanoi

hanoi(n-1,one,there,two); //是把前N-1个从1先经过3在移到2;
move(one,three); //把第N个移到3;
hanoi(n-1,two,one,three);
//是把这N-1个从2先经过1在移到3;

你看看递归调用的一些知识,你就可以看懂了!