1 #include <iostream>
2
3 using namespace std;
4
5 int count=1;
6 void move(int n,char from,char to) //将编号为n的盘子由from移动到to
7 {
8 printf("%d:Move disk %d:From%c---->%c\n",count++,n,from,to);
9 }
10
11 void hanoi(int n,char x,char y,char z)
12 {
13
14 if(n==1)
15 {
16 move(n,x,z);
17 return;
18 }
19
20 else {
21 hanoi(n-1,x,z,y);// 把源塔的n-1个盘子移动到中间塔
22 move(n,x,z);
23 hanoi(n-1,y,x,z);// 把中间塔的n-1个盘子移动到中间塔
24 }
25 }
26 int main()
27 {
28 char X='X';
29 char Y='Y';
30 char Z='Z';
31 hanoi(10,X,Y,Z);//修改圆盘的数值
32 return 0;
33 }