汉诺塔

来源:互联网 发布:淘宝客服犯错奖罚制度 编辑:程序博客网 时间:2024/06/16 08:25

汉诺塔

void move(char x,char y){cout<<x<<"-->"<<y<<endl;}void hanoi(int n,char one,char two,char three)//将 n 个盘从 one 座借助 two 座,移到 three 座{if(n==1) move(one,three);else{hanoi(n-1,one,three,two);move(one,three);hanoi(n-1,two,one,three);}}int main()
{
int m;
cout<<"input the number of diskes:";
cin>>m;
cout<<"The steps of moving "<<m<<" disks:"<<endl;
hanoi(m,'A','B','C');
return 0;
}


0 0
原创粉丝点击