xt4-9.cpp
上传用户:liubin
上传日期:2022-06-13
资源大小:85k
文件大小:1k
- #include <iostream>
- using namespace std;
- int main()
- {void hanoi(int n,char one,char two,char three);
- int m;
- cout<<"input the number of diskes:";
- 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)
- //将n个盘从one座借助two座,移到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;}