正在加载图片...
maino 3ABC O printf("Input the number of disks) scanf(%d", &m) A B printf("Steps: %03d disks, m) bAC 8 hanoi(m, A, B, C) (0)} 3ABIC O yoid hanoi (int n, char x, char y, char Z 1BCA6 2baC 8 2)ifn=1) ) 3ABCO novell.X.Z 4) else hanoi(n-1,x, Z, y); move(n, x, z) A B hanoi(n-ly,,Z) 8) 2BALC (9)} 3ABCOmain() { 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 3 A B C 0 2 B A C 8 1 B C A 6 A B C 3 A B C 0 2 B A C 8 3 A B C 0
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有