汉诺塔问题的ppt详解

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

//汉诺塔ABCABC//汉诺塔ABC//汉诺塔ABC//汉诺塔ABC//汉诺塔ABC//汉诺塔ABC//汉诺塔ABC//汉诺塔ABC//汉诺塔ABC//汉诺塔ABC//汉诺塔ABC//汉诺塔//汉诺塔#includestdio.hvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n”,a,c);hanoi(n-1,b,a,c);}}voidmain(){intn;printf(Inputthenumberofdiskes:\n“);scanf(“%d”,&n);hanoi(n,'A','B','C');}StacknabcOutput//汉诺塔voidmain(){intn;printf(Inputthenumberofdiskes:\n“);scanf(“%d”,&n);hanoi(n,'A','B','C');}StacknabcH(3,A,B,C)3ABCOutputH(n,A,B,C)//汉诺塔voidmain(){intn;printf(Inputthenumberofdiskes:\n“);scanf(“%d”,&n);hanoi(n,'A','B','C');}StacknabcH(3,A,B,C)3ABCOutputH(n,A,B,C)voidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}//汉诺塔StacknabcH(3,A,B,C)3ABC2ACB1ABCOutputH(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)0ACBH(2,A,C,B)H(1,A,B,C)voidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBH(1,A,B,C)1ABCOutputH(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)0ACBvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBH(1,A,B,C)1ABCOutputACH(n,A,B,C)H(n-1,a,c,b)H(n-1,a,c,b)coutvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBH(1,A,B,C)1ABCOutputA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)0BACvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBH(1,A,B,C)1ABCOutputA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)0BACvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBH(1,A,B,C)1ABCOutputACH(n,A,B,C)H(n-1,a,c,b)H(n-1,a,c,b)voidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)coutvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)1CABH(n-1,b,a,c)H(1,C,A,B)voidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1CABH(n-1,b,a,c)H(0,C,B,A)H(n-1,a,c,b)0CBAvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1CABH(n-1,b,a,c)H(0,C,B,A)H(n-1,a,c,b)0CBAvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1CABH(n-1,b,a,c)CBcoutvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1CABH(n-1,b,a,c)CBH(0,A,C,B)H(n-1,b,a,c)0ACBvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1CABH(n-1,b,a,c)CBH(0,A,C,B)H(n-1,b,a,c)0ACBvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1CABH(n-1,b,a,c)CBvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)CBvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCH(2,A,C,B)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)CBACcoutvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCOutputACABH(n,A,B,C)CBH(2,B,A,C)2BACH(n-1,b,a,c)ACvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCOutputACABH(n,A,B,C)CBH(2,B,A,C)2BAC1BCAH(n-1,b,a,c)H(n-1,a,c,b)ACH(0,B,A,C)H(n-1,a,c,b)0BACH(1,B,C,A)voidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCOutputACABH(n,A,B,C)CBH(2,B,A,C)2BACH(1,B,C,A)1BCAH(n-1,b,a,c)H(n-1,a,c,b)ACH(0,B,A,C)H(n-1,a,c,b)0BACvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCOutputACABH(n,A,B,C)CBH(2,B,A,C)2BACH(1,B,C,A)1BCAH(n-1,b,a,c)H(n-1,a,c,b)ACBAcoutvoidhanoi(intn,chara,charb,charc){if(n=1){hanoi(n-1,a,c,b);printf(“%c--%c\n“,a,c);hanoi(n-1,b,a,c);}}StacknabcH(3,A,B,C)3ABCOutputACABH(n,A,B,C)CBH(2,B,A,C)2BACH(1,B,C,A)1BCAH(n-1,b,a,c)H(n-1,a,c,b)ACB

1 / 50
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功