正在加载图片...
maino 2BAC 8 int m 3ABCO printf("input the number of disks); scanf("%d", &m) 1ABC 8 printf("Steps: %3d disks', m) bAC 8 hanoi(m, a,B,C) 3ABCO void hanoi (int n, char x, char y, char z A B 3) move( l x. z) 2BAC8 (4)else ABC O (5) hanoi(n-1, x, z,y) (6) move(n, x, z) (7) hanoi(n-1,,x,z); 3AT B|C|0 8)} 栈空main() { int m; printf("Input the number of disks”); scanf("%d",&m); printf(" Steps : %3d disks”,m); 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 B A C 8 1 A B C 8 A B C 3 A B C 0 2 B A C 8 3 A B C 0 栈空 3 A B C 0 2 B A C 8
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有