- /***************************************************************
- * *
- * 作者:祝靖俊 *
- * 描述:漢諾塔的遞歸實現 *
- * 實現語言:C++ *
- * 運行環境:標準C++運行環境 *
- * *
- ***************************************************************/
- #include <iostream>
- using namespace std;
- void hannoi(int count, char* target, char* from, char* temp);
- void move(int count, char* target, char* from);
- int main(){
- hannoi(3, "target", "from", "temp");
- return 0;
- }
- void hannoi(int count, char* target, char* from, char* temp){
- if(count==1){
- move(count, target, from);
- }else{
- hannoi(count-1, temp, from, target);
- move(count, target, from);
- hannoi(count-1, target, temp, from);
- }
- }
- void move(int count, char* target, char* from){
- cout << "把" << count << "從" << from << "移動到" << target << endl;
- }