Asp.net 学习资料

伦惠峰

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');
}

posted on 2007-08-13 21:34  伦惠峰  阅读(148)  评论(0)    收藏  举报

导航