2
0

汉诺塔问题 求助

PC技术交流2022-09-16 16:07天津
6502
盲盒,非粘贴。

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

// 汉诺塔  
#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;
}
正纠结:是用两个打印输出,还是用两个调用?
全部回复 2
proof

主题: 16

回复: 14

关注: 0

粉丝: 0

TA 的积分
  • 241
  • 1
  • 0