您好,欢迎访问三七文档
当前位置:首页 > IT计算机/网络 > 数据库 > 汉诺塔问题的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)1ABCOutputACH(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)1ABCOutputACH(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)1ABCOutputACH(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)1ABCOutputACH(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)2ACBOutputACABH(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)2ACBOutputACABH(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)2ACBOutputACABH(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)2ACBOutputACABH(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)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1CABH(n-1,b,a,c)CBcoutvoidhanoi(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)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1CABH(n-1,b,a,c)CBH(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)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1CABH(n-1,b,a,c)CBH(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)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)H(1,C,A,B)1CABH(n-1,b,a,c)CBvoidhanoi(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)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)CBvoidhanoi(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)2ACBOutputACABH(n,A,B,C)H(n-1,a,c,b)CBACcoutvoidhanoi(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)3ABCOutputACABH(n,A,B,C)CBH(2,B,A,C)2BACH(n-1,b,a,c)ACvoidhanoi(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)3ABCOutputACABH(n,A,B,C)CBH(2,B,A,C)2BAC1BCAH(n-1,b,a,c)H(n-1,a,c,b)ACH(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)3ABCOutputACABH(n,A,B,C)CBH(2,B,A,C)2BACH(1,B,C,A)1BCAH(n-1,b,a,c)H(n-1,a,c,b)ACH(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)3ABCOutputACABH(n,A,B,C)CBH(2,B,A,C)2BACH(1,B,C,A)1BCAH(n-1,b,a,c)H(n-1,a,c,b)ACBAcoutvoidhanoi(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)3ABCOutputACABH(n,A,B,C)CBH(2,B,A,C)2BACH(1,B,C,A)1BCAH(n-1,b,a,c)H(n-1,a,c,b)ACB
本文标题:汉诺塔问题的ppt详解
链接地址:https://www.777doc.com/doc-4080318 .html