正文

汉诺塔递归算法2006-07-30 02:45:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/petibo/16996.html

分享到:

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

阅读(2580) | 评论(3)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册