proof1 发表于 2022-9-16 16:07

汉诺塔问题 求助


盲盒,非粘贴。

请分析一下我这个思路,做出更正。

// 汉诺塔
#include <iostream>
#include <cstring>
using namespace std;

void move(int s , char a , char b , char c){
    if (s==1) return;
    cout<<a<<"--"<<b<<endl;
    move(s-1,a,c,b);
    cout<<a<<"--"<<c<<endl;
          
}

int main(){
    int n=4;

        move(n,'a','b','c');// 4层盘,从a杆开始,以b杆为中介,移动到c杆
       
    return 0;
}

正纠结:是用两个打印输出,还是用两个调用?
页: [1]
查看完整版本: 汉诺塔问题 求助