Hanoi_Tower汉诺塔—每日算法档

Mhhao

关注

阅读 73

2022-03-30

在这里插入图片描述
在这里插入图片描述
思想:使用递归的思想 ,将里面 需要中间变量需要来当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)

0 0 举报