汉诺塔问题的ppt详解课件.ppt
《汉诺塔问题的ppt详解课件.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 ) ; v
2、oid main () int n ; printf( Input the number of diskes:n “) ; scanf(“%d”,&n) ; hanoi ( n, A , B , C ) ; StackOutput/ 汉诺塔汉诺塔 void main () int n ; printf( Input the number of diskes:n “) ; scanf(“%d”,&n) ; hanoi ( n, A , B , C ) ; StackH ( 3, A, B, C )3 A B COutputH(n,A,B,C)/ 汉诺塔汉诺塔 void main () int n
3、 ; printf( Input the number of diskes:n “) ; scanf(“%d”,&n) ; hanoi ( n, A , B , C ) ; StackH ( 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) ; / 汉诺塔汉诺塔StackH ( 3, A, B, C )3 A B C2 A C
4、 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 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) ; StackH ( 3, A, B, C )3 A B CH ( 2, A, C, B )2 A C BH ( 1
5、, 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) ; printf(“%c -%cn“,a,c); hanoi (n-1, b, a, c) ; StackH ( 3, A, B, C )3 A B CH ( 2, A, C, B )2 A C BH ( 1, A, B, C )1 A B COutpu
6、tA 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) ; StackH ( 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)H ( 0, B , A,
7、 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) ; StackH ( 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)H ( 0, B , A, C )H(n-1,b,a,c)0 B
8、 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) ; StackH ( 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
9、 = 1 ) hanoi ( n-1, a, c, b) ; printf(“%c -%cn“,a,c); hanoi (n-1, b, a, c) ; StackH ( 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) ; StackH
10、 ( 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)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) ; StackH ( 3, A, B, C )3 A B CH ( 2, A, C, B )2 A C BOutputA
11、 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 ) hanoi ( n-1, a, c, b) ; printf(“%c -%cn“,a,c); hanoi (n-1, b, a, c) ; StackH ( 3, A, B, C )3 A B CH ( 2, A, C, B )2 A C BOutputA CA BH(n,A,B,C)H(
12、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 ) hanoi ( n-1, a, c, b) ; printf(“%c -%cn“,a,c); hanoi (n-1, b, a, c) ; StackH ( 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,
13、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) ; StackH ( 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 ,
14、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) ; StackH ( 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,
15、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) ; StackH ( 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 hanoi ( int n, char a, char b, char
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 汉诺塔 问题 ppt 详解 课件
限制150内