#include <iostream.h>void move(char getone,char putone){ cout<<getone<<"-->"<<putone<<endl;}void hanoi(int n,char one,char two,char three){ void move(char getone,char putone); if(n==1)move (one ,three); else { hanoi(n-1,one, three,two); move(one ,three); hanoi(n-1,two,one ,three); }}void main(){ void hanoi(int n,char one,char two,char three); int m; cout<<"请输入汉诺塔的级数:"; cin>>m; cout<<"移动"<<m<<"盘子的方法:"<<endl; hanoi(m,'A','B','C');}

评论