0
点赞
收藏
分享

微信扫一扫

Hanoi_Tower汉诺塔—每日算法档

Mhhao 2022-03-30 阅读 73

在这里插入图片描述
在这里插入图片描述
思想:使用递归的思想 ,将里面 需要中间变量需要来当tmp缓存变量

#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<cmath>
using namespace std;
void deal(int n, char start, char towards, char zhong){
    if (n==0) 
    {
        return ;
    }
    deal(n-1,start, zhong, towards);
    printf("move No.%d from %c to %c\n", n, start, towards);
    deal(n-1, zhong, towards,start);
}

int main(){
    deal(4,'A','C','B');
    return 0;
}
举报

相关推荐

0 条评论