以前看过汉诺塔不过没看懂。。昨天上机问老师勉强看懂了

来源:互联网 发布:亦强软件报价 编辑:程序博客网 时间:2024/04/30 12: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 onr,char two,char three);   int m;   cout<<"enter the number of diskes:";   cin>>m;   cout<<"the step of moving"<<m<<"diskes:"<<endl;   hanoi(m,'A','B','C');   system("pause");   return 0;}

运行结果: