資源描述:
《漢諾塔的圖形解法》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、漢諾塔的圖形解法#include"stdio.h"#include"dos.h"#include"conio.h"/*定義兩個(gè)數(shù)組a[4][11],b[4],其中a[4][11]用來指向柱子上的內(nèi)容(碟片),b[4]用來標(biāo)志柱子上的碟片高度*/inta[4][11]={{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0}},b[4]={0,0,0,0};FILE*TEMP;/*定義一個(gè)移除碟片的函數(shù),vo
2、idremovef(起始位置,高度,碟片的大小)*********************************/voidremovef(charstart,intheight,intsize){????????intzb_x;????????textbackground(3);????????switch(start)????????{??????????????????case'A':zb_x=11;break;??????????????????case'B':zb_x=32;break;??????????????????case
3、'C':zb_x=53;break;????????}????????for(;size>0;size--)????????{??????????????????gotoxy(zb_x-size,11-height);??????????????????cprintf("%c",0);??????????????????gotoxy(zb_x+size,11-height);??????????????????cprintf("%c",0);????????}???delay(35000);}/*定義一個(gè)重建碟片的函數(shù),voidcreate
4、f(移動(dòng)到位置,高度,碟片的大小)*******************************/voidcreatef(charend,intheight,intsize){????????intzb_x;????????textbackground(0);????????switch(end)????????{??????????????????case'A':zb_x=11;break;??????????????????case'B':zb_x=32;break;??????????????????case'C':zb_x=53;b
5、reak;????????}????????for(;size>0;size--)????????{??????????????????gotoxy(zb_x-size,11-height);??????????????????cprintf("%c",0);??????????????????gotoxy(zb_x+size,11-height);??????????????????cprintf("%c",0);????????}????????delay(35000);}/*漢諾塔遞歸算法,并講結(jié)果寫入文件指針TEMP指向的文件***
6、******************************************/intmove(intN,intA,intB,intC){???if(N==1)???{?????fputc(A,TEMP);?????fputc(C,TEMP);??????}???else???{?????move(N-1,A,C,B);?????fputc(A,TEMP);?????fputc(C,TEMP);?????move(N-1,B,A,C);???}}main(){????????voidremovef(char,int,int);????
7、????voidremovef(char,int,int);????????intmove(int,int,int,int);???intN,i,j,k,m,n,hei,counter=0,height0,height1,size,disksize;???charcur_char;???/*建立一個(gè)用于存儲(chǔ)遞歸函數(shù)輸出的文件********************************************************/???TEMP=fopen("D:\MDL.txt","w");???fclose(TEMP);???/
8、*讓用戶輸入漢諾塔的層數(shù),并初始化a[1][]的內(nèi)容***********************************************/???printf("inpu