==此博客代码思想参考了严蔚敏老师的教材,特此声明==
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <stack>
using namespace std;
int c = 1;
void hanoi_move(char x,int n,char z){ //把编号为n的圆盘从x移到z
printf("%d . Move disk %d from %c to %c\n",c++,n,x,z);
}
//将塔座x上按直径由小到大且自上向下编号为1至n的n个圆盘按规则搬到
//塔座z上,y可用作辅助塔座
void hanoi_problem(int n,char x,char y,char z){
if(n == 1){
hanoi_move(x,1,z);
}else{
hanoi_problem(n-1,x,z,y);
hanoi_move(x,n,z);
hanoi_problem(n-1,y,x,z);
}
}
int main(){
hanoi_problem(3,'x','y','z');
return 0;
}