Download
hanoi executing n.
Skip this Video
Loading SlideShow in 5 Seconds..
Hanoi executing PowerPoint Presentation
Download Presentation
Hanoi executing

Hanoi executing

77 Vues Download Presentation
Télécharger la présentation

Hanoi executing

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Hanoi executing

  2. 0 1 Hanoi(2,a,c,b) Hanoi(3,a,b,c) move (a,3,c) Hanoi(2,b,a,c)

  3. 0 1 Hanoi(2,a,c,b) Hanoi(3,a,b,c) move (a,3,c) Hanoi(2,b,a,c) 2 Hanoi(1,a,b,c) move(a,2,b) Hanoi(1,c,a,b)

  4. 0 1 2 Hanoi(1,a,b,c) Hanoi(2,a,c,b) move(a,2,b) Hanoi(1,c,a,b) Hanoi(3,a,b,c) move (a,3,c) Hanoi(2,b,a,c) 3 move(a,1,c) move(c,1,b)

  5. 0 1 2 3 Hanoi(1,a,b,c) move(a,1,c) Hanoi(2,a,c,b) move(a,2,b) Hanoi(1,c,a,b) move(c,1,b) Hanoi(3,a,b,c) move (a,3,c) Hanoi(2,b,a,c) Hanoi(1,b,c,a) move(b,2,c) Hanoi(1,a,b,c)

  6. 0 1 2 3 Hanoi(1,a,b,c) move(a,1,c) Hanoi(2,a,c,b) move(a,2,b) Hanoi(1,c,a,b) move(c,1,b) Hanoi(3,a,b,c) move (a,3,c) Hanoi(1,b,c,a) move(b,1,a) Hanoi(2,b,a,c) move(b,2,c) move(a,1,c) Hanoi(1,a,b,c)

  7. Hanoi(3,a,b,c) Hanoi(1,a,b,c) move(a,2,b) Hanoi(2,a,c,b) Hanoi(1,c,a,b)

  8. Hanoi(1,b,c,a) a c b 2 1 3 move (a,3,c) move(b,2,c) Hanoi(2,b,a,c) Hanoi(1,c,a,b)

  9. 0 tier void main (void) { int n; unsigned char a,b,c; n=3; a=1; b=2; c=3; hanoi(n, a, b, c); 0: . . . }

  10. 0 tier void main (void) { int n; unsigned char a,b,c; n=3; a=1; b=2; c=3; hanoi(n, a, b, c); 0: . . . }

  11. 0 tier void main (void) { int n; unsigned char a,b,c; n=3; a=1; b=2; c=3; hanoi(n, a, b, c); 0: . . . }

  12. 0 tier void main (void) { int n; unsigned char a,b,c; n=3; a=1; b=2; c=3; hanoi(n, a, b, c); 0: . . . }

  13. 0 tier void main (void) { int n; unsigned char a,b,c; n=3; a=1; b=2; c=3; hanoi(n, a, b, c); 0: } 0, 3, a, b, c

  14. 1 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 3, a, b, c 0, 3, a, b, c

  15. 1 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 3, a, b, c 0, 3, a, b, c

  16. 1 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 3, a, b, c 0, 3, a, b, c

  17. 1 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 3, a, b, c 2, a, c, b 0, 3, a, b, c

  18. 1 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 3, a, b, c 2, a, c, b 6, 2, a, c, b 0, 3, a, b, c

  19. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, a, c, b 6, 2, a, c, b 0, 3, a, b, c

  20. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, a, c, b 6, 2, a, c, b 0, 3, a, b, c

  21. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, a, c, b 6, 2, a, c, b 0, 3, a, b, c

  22. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, a, c, b 1, a, b, c 6, 2, a, c, b 0, 3, a, b, c

  23. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, a, c, b 1, a, b, c 6, 1, a, b, c 6, 2, a, c, b 0, 3, a, b, c

  24. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, a, b, c 6, 1, a, b, c 6, 2, a, c, b 0, 3, a, b, c

  25. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, a, b, c 6, 1, a, b, c 6, 2, a, c, b 0, 3, a, b, c

  26. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, a, b, c a, 1, c 6, 1, a, b, c 6, 2, a, c, b 0, 3, a, b, c

  27. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, a, b, c 6, 1, a, b, c 6, 2, a, c, b 0, 3, a, b, c

  28. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, a, c, b a, 2, b 6, 2, a, c, b 0, 3, a, b, c

  29. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, a, c, b 6, 2, a, c, b 1,c,a,b 0, 3, a, b, c

  30. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, a, c, b 8, 1, c, a, b 6, 2, a, c, b 1,c,a,b 0, 3, a, b, c

  31. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, c, a, b 8, 1, c, a, b 6, 2, a, c, b 0, 3, a, b, c

  32. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, c, a, b 8, 1, c, a, b 6, 2, a, c, b 0, 3, a, b, c

  33. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, c, a, b c, 1, b 8, 1, c, a, b 6, 2, a, c, b 0, 3, a, b, c

  34. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, c, a, b 8, 1, c, a, b 6, 2, a, c, b 0, 3, a, b, c

  35. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, a, c, b 6, 2, a, c, b 0, 3, a, b, c

  36. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, a, c, b 6, 2, a, c, b 0, 3, a, b, c

  37. 1 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 3, a, b, c a, 3, c 0, 3, a, b, c

  38. 1 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 3, a, b, c 2, b, a, c 0, 3, a, b, c

  39. 1 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 3, a, b, c 8, 2, b, a, c 2, b, a, c 0, 3, a, b, c

  40. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, b, a, c 8, 2, b, a, c 0, 3, a, b, c

  41. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, b, a, c 8, 2, b, a, c 0, 3, a, b, c

  42. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, b, a, c 8, 2, b, a, c 0, 3, a, b, c

  43. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, b, a, c 1, b, c, a 8, 2, b, a, c 0, 3, a, b, c

  44. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, b, a, c 1, b, c, a 6, 1, b, c, a 8, 2, b, a, c 0, 3, a, b, c

  45. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, b, c, a 6, 1, b, c, a 8, 2, b, a, c 0, 3, a, b, c

  46. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, b, c, a 6, 1, b, c, a 8, 2, b, a, c 0, 3, a, b, c

  47. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, b, c, a b, 1, a 6, 1, b, c, a 8, 2, b, a, c 0, 3, a, b, c

  48. 3 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 1, b, c, a 6, 1, b, c, a 8, 2, b, a, c 0, 3, a, b, c

  49. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, b, a, c b,2,c 8, 2, b, a, c 0, 3, a, b, c

  50. 2 tier • void hanoi(int n, char x, char y, char z) • 1 { • 2 if(n==1) • 3 move(x,1,z); • 4 else{ • 5 hanoi(n-1,x,z,y); • move(x,n,z); • hanoi(n-1,y,x,z); • 8 } • 9 } 2, b, a, c 8, 2, b, a, c 1,a,b,c 0, 3, a, b, c