阳光裹进被里

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#include
<stdio.h>

/**
 * Tower of Hanoi 汉诺塔
 * @param n The count of plates
 * @param src The source of the plates to move from
 * @param dest The destination of the plates to move to
 * @param tmp The temporary place to use
 */
void Move(int n, char src, char dest, char tmp) {
    if (n == 0) return;
    else if (n == 1) printf("%c --> %c\n", src, dest);
    else {
        Move(n - 1, src, tmp, dest);
        Move(1, src, dest, tmp);
        Move(n - 1, tmp, dest, src);
    }
}

int main() {
    Move(3, 'A', 'C', 'B');
    return 0;
}


posted on 2021-12-20 13:56  阳光裹进被里  阅读(45)  评论(0)    收藏  举报