正在加载图片...
mall IC 6 i int m 3ABIC O printf("Input the number of disks B scanf(" %od", &m) printf("The steps to moving %/03d 1C|A|B|8 hanoi(m,A, B,C) 2ACBI 6 (0)} 3ABCO void hanoi(int n, char x, char y, char z (2)if(n=1) move(l,xz). B (4) else& (5 hanoi(n-1,x, z,y); 2ACB6 move(n, x, z); 3ABCO hanoi(n-1y, z) 3ABCI O (9)}main() { int m; printf("Input the number of disks scanf("%d",&m); printf("The steps to moving %3d hanoi(m,'A','B','C'); (0) } void hanoi(int n,char x,char y,char z) (1) { (2) if(n==1) (3) move(1,x,z); (4) else{ (5) hanoi(n-1,x,z,y); (6) move(n,x,z); (7) hanoi(n-1,y,x,z); (8) } (9) } A B C 3 A B C 0 2 A C B 6 1 C A B 8 A B C 3 A B C 0 2 A C B 6 3 A B C 0 3 A B C 0 2 A C B 6
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有