汉诺塔问题的详解.ppt

上传人:可**** 文档编号:84688836 上传时间:2023-04-06 格式:PPT 页数:50 大小:500KB
返回 下载 相关 举报
汉诺塔问题的详解.ppt_第1页
第1页 / 共50页
汉诺塔问题的详解.ppt_第2页
第2页 / 共50页
点击查看更多>>
资源描述

《汉诺塔问题的详解.ppt》由会员分享,可在线阅读,更多相关《汉诺塔问题的详解.ppt(50页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、/汉诺塔汉诺塔 ABCABC/汉诺塔汉诺塔 ABC/汉诺塔汉诺塔 ABC/汉诺塔汉诺塔 ABC/汉诺塔汉诺塔 ABC/汉诺塔汉诺塔 ABC/汉诺塔汉诺塔 ABC/汉诺塔汉诺塔 ABC/汉诺塔汉诺塔 ABC/汉诺塔汉诺塔 ABC/汉诺塔汉诺塔 ABC/汉诺塔汉诺塔/汉诺塔汉诺塔#include void hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn”,a,c);hanoi(n-1,b,a,c);void main()int n;printf(Input the number of diskes:n

2、“);scanf(“%d”,&n);hanoi(n,A,B,C);Stackn a b cn a b cOutput/汉诺塔汉诺塔 void main()int n;printf(Input the number of diskes:n“);scanf(“%d”,&n);hanoi(n,A,B,C);Stackn a b cn a b cH(3,A,B,C)3 A B COutputH(n,A,B,C)/汉诺塔汉诺塔 void main()int n;printf(Input the number of diskes:n“);scanf(“%d”,&n);hanoi(n,A,B,C);Stac

3、kn a b cn a b cH(3,A,B,C)3 A B COutputH(n,A,B,C)void hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);/汉诺塔汉诺塔Stackn a b cn a b cH(3,A,B,C)3 A B C2 A C B1 A B COutputH(n,A,B,C)H(n-1,a,c,b)H(n-1,a,c,b)H(0,A,C,B)H(n-1,a,c,b)0 A C BH(2,A,C,B)H(1,A,B,C)void

4、hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BH(1,A,B,C)1 A B COutputH(n,A,B,C)H(n-1,a,c,b)H(n-1,a,c,b)H(0,A,C,B)H(n-1,a,c,b)0 A C Bvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);pr

5、intf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BH(1,A,B,C)1 A B COutputA CH(n,A,B,C)H(n-1,a,c,b)H(n-1,a,c,b)coutvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)

6、2 A C BH(1,A,B,C)1 A B COutputA CH(n,A,B,C)H(n-1,a,c,b)H(n-1,a,c,b)H(0,B,A,C)H(n-1,b,a,c)0 B A Cvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BH(1,A,B,C)1 A B COutputA CH(n,A,B,C)H(n-1,a,c,b)H(

7、n-1,a,c,b)H(0,B,A,C)H(n-1,b,a,c)0 B A Cvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BH(1,A,B,C)1 A B COutputA CH(n,A,B,C)H(n-1,a,c,b)H(n-1,a,c,b)void hanoi(int n,char a,char b,char c)if (n=1)h

8、anoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BOutputA CA BH(n,A,B,C)H(n-1,a,c,b)coutvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BO

9、utputA CA BH(n,A,B,C)H(n-1,a,c,b)1 C A BH(n-1,b,a,c)H(1,C,A,B)void hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BOutputA CA BH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1 C A BH(n-1,b,a,c)H(0,C,B,A)H(n-1,a,c,b

10、)0 C B Avoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BOutputA CA BH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1 C A BH(n-1,b,a,c)H(0,C,B,A)H(n-1,a,c,b)0 C B Avoid hanoi(int n,char a,char b,char c)if (n=1)

11、hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BOutputA CA BH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1 C A BH(n-1,b,a,c)C Bcoutvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(

12、3,A,B,C)3 A B CH(2,A,C,B)2 A C BOutputA CA BH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1 C A BH(n-1,b,a,c)C BH(0,A,C,B)H(n-1,b,a,c)0 A C Bvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BOutputA CA BH(n,A,B

13、,C)H(n-1,a,c,b)H(1,C,A,B)1 C A BH(n-1,b,a,c)C BH(0,A,C,B)H(n-1,b,a,c)0 A C Bvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BOutputA CA BH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1 C A BH(n-1,b,a,c)C Bvoid

14、 hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BOutputA CA BH(n,A,B,C)H(n-1,a,c,b)C Bvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b c

15、n a b cH(3,A,B,C)3 A B CH(2,A,C,B)2 A C BOutputA CA BH(n,A,B,C)H(n-1,a,c,b)C BA Ccoutvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(n-1,b,a,c)A Cvoid hanoi(int n,char

16、 a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A C1 B C AH(n-1,b,a,c)H(n-1,a,c,b)A CH(0,B,A,C)H(n-1,a,c,b)0 B A CH(1,B,C,A)void hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf

17、(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(1,B,C,A)1 B C AH(n-1,b,a,c)H(n-1,a,c,b)A CH(0,B,A,C)H(n-1,a,c,b)0 B A Cvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a

18、b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(1,B,C,A)1 B C AH(n-1,b,a,c)H(n-1,a,c,b)A CB Acoutvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(1,B,C,

19、A)1 B C AH(n-1,b,a,c)H(n-1,a,c,b)A CB AH(0,C,B,A)H(n-1,b,a,c)0 C B Avoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(1,B,C,A)1 B C AH(n-1,b,a,c)H(n-1,a,c,b)A CB AH(0,C,

20、B,A)H(n-1,b,a,c)0 C B Avoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(1,B,C,A)1 B C AH(n-1,b,a,c)H(n-1,a,c,b)A CB Avoid hanoi(int n,char a,char b,char c)if (n=1)hanoi

21、(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(1,B,C,A)1 B C AH(n-1,b,a,c)H(n-1,a,c,b)A CB AB Ccoutvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b

22、 cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(n-1,b,a,c)A CB A1 A B CH(n-1,b,a,c)B CH(1,A,B,C)void hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(n-1,b,a,

23、c)A CB AH(1,A,B,C)1 A B CH(n-1,b,a,c)B CH(0,A,C,B)H(n-1,a,c,b)0 A C Bvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(n-1,b,a,c)A CB AH(1,A,B,C)1 A B CH(n-1,b,a,c)B CH(

24、0,A,C,B)H(n-1,a,c,b)0 A C Bvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(n-1,b,a,c)A CB AH(1,A,B,C)1 A B CH(n-1,b,a,c)B CA Ccoutvoid hanoi(int n,char a,char b,char c

25、)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);/汉诺塔汉诺塔void hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);couta c=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(n-1,b,a,c)A CB A1 A B

26、 CB CA CH(1,A,B,C)H(n-1,b,a,c)void hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(n,A,B,C)C BH(2,B,A,C)2 B A CH(n-1,b,a,c)A CB AB CA Cvoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);prin

27、tf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);Stackn a b cn a b cH(3,A,B,C)3 A B COutputA CA BH(3,A,B,C)C BA CB AB CA COvervoid hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);OverStackn a b cn a b cOutputA CA BC BA CB AB CA C/汉诺塔汉诺塔void hanoi(int n,char a,char b,char c)if (n=1)hanoi(n-1,a,c,b);printf(“%c-%cn“,a,c);hanoi(n-1,b,a,c);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 初中资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁