#include <stdio.h> //移動步驟計(jì)數(shù) static int number = 0; /* * 借助于x,從from移動n個到to * * n 要移動的個數(shù) * from 初始的位置 * to 移動之后的文件 * x 需要借助的位置 * */ void hanluota(int n, char from, char to, char x) { if(n <= 1) { printf("%d : %c --> %c\n", number++, from, to); return; } //把from上的n-1個移動到x暫存 hanluota(n-1, from, x, to); //把from最下面的一個移動到to printf("%d : %c --> %c\n", number++, from, to); //把x上的n-1個移動到to hanluota(n-1, x, to, from); } int main(void) { hanluota(3, 'a', 'b', 'c'); printf("finished"); getchar(); return 0; } |
|