Hanoi问题
#include<iostream.h>
void move(char x,char y)
{
//cout<<x<<"-->"<<y<<endl;
}
void hanoi(int n,char one,char two,char three)
{
if(n==1) move(one,three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
void main()
{
int m;
cout<<"input the number of disk"<<endl;
cin>>m;
cout<<"The step to moving"<<m<<" diskes"<<endl;
hanoi(m,'A','B','C');
}
void move(char x,char y)
{
//cout<<x<<"-->"<<y<<endl;
}
void hanoi(int n,char one,char two,char three)
{
if(n==1) move(one,three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
void main()
{
int m;
cout<<"input the number of disk"<<endl;
cin>>m;
cout<<"The step to moving"<<m<<" diskes"<<endl;
hanoi(m,'A','B','C');
}
浙公网安备 33010602011771号