汉诺塔问题的详解.ppt
《汉诺塔问题的详解.ppt》由会员分享,可在线阅读,更多相关《汉诺塔问题的详解.ppt(50页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 汉诺塔 问题 详解
限制150内