




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、課課 程程 設(shè)設(shè) 計(jì)計(jì) 報(bào)報(bào) 告告 課程設(shè)計(jì)名稱:數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì) 課程設(shè)計(jì)題目: 長整數(shù)的代數(shù)計(jì)算長整數(shù)的代數(shù)計(jì)算 院(系): 專 業(yè):計(jì)算機(jī)科學(xué)與技術(shù) 班 級(jí): 學(xué) 號(hào): 姓 名: 指導(dǎo)教師: 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 目目 錄錄 1 題目介紹和功能要求題目介紹和功能要求.1 1.1 題目介紹 .1 1.2 功能要求 .1 1.3 基本功能 .1 2 系統(tǒng)功能模塊結(jié)構(gòu)圖系統(tǒng)功能模塊結(jié)構(gòu)圖.2 2.1 系統(tǒng)功能結(jié)構(gòu)框圖.2 2.2 系統(tǒng)主要模塊的功能說明.2 3 使用的數(shù)據(jù)結(jié)構(gòu)的描述使用的數(shù)據(jù)結(jié)構(gòu)的描述.4 3.1 數(shù)據(jù)結(jié)構(gòu)設(shè)計(jì) .4 3.2 數(shù)據(jù)結(jié)構(gòu)用法說明 .4 4
2、函數(shù)的描述函數(shù)的描述.5 4.1 主要函數(shù)設(shè)計(jì).5 4.2 主要函數(shù)流程圖.6 5 程序測試和運(yùn)行的結(jié)果程序測試和運(yùn)行的結(jié)果.11 5.1 程序測試.11 5.2 運(yùn)行結(jié)果.12 6 參考文獻(xiàn)參考文獻(xiàn).14 附附 錄(關(guān)鍵部分程序清單)錄(關(guān)鍵部分程序清單).15 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 0 1 題目介紹和功能要求 1.1 題目介紹題目介紹 設(shè)計(jì)數(shù)據(jù)結(jié)構(gòu)完成長整數(shù)的表示和存儲(chǔ),并編寫算法來實(shí)現(xiàn)兩個(gè)長整數(shù)的 加、減、乘、除等基本代數(shù)運(yùn)算。 1.2 功能要求功能要求 1) 長整數(shù)長度在一百位以上。 2) 實(shí)現(xiàn)兩長整數(shù)在同余代數(shù)下的加、減、乘、除操作。即實(shí)現(xiàn)算法來求解 a+b mod n,a-
3、b mod n,a*b mod n,ab mod n。 3)輸入輸出均在文件中。 (選作) 1.3 基本功能基本功能 1.jiafa(); 將一百位以上的長整數(shù)進(jìn)行加法運(yùn)算,計(jì)算出和。 2.jianfa(); 將一百位以上的長整數(shù)進(jìn)行減法運(yùn)算,計(jì)算出差。 3.chenfa(); 將一百位以上的長整數(shù)進(jìn)行乘法運(yùn)算,計(jì)算出積。 4.chufa(); 將一百位以上的長整數(shù)進(jìn)行除法運(yùn)算,計(jì)算出商和余數(shù)。 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 1 2 系統(tǒng)功能模塊結(jié)構(gòu)圖 2.1 系統(tǒng)功能結(jié)構(gòu)框圖系統(tǒng)功能結(jié)構(gòu)框圖 主模塊 輸入模塊 減 法 模 塊 加 法 模 塊 乘 法 模 塊 除 法 模 塊 輸出模塊 圖圖 2
4、.12.1 系統(tǒng)功能結(jié)構(gòu)框圖系統(tǒng)功能結(jié)構(gòu)框圖 2.2 系統(tǒng)主要模塊的功能說明系統(tǒng)主要模塊的功能說明 1. 主模塊 kongzhi(); 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 2 控制輸入模塊、加法模塊、減法模塊、乘法模塊、除法模塊、輸出模塊 的循環(huán)使用。 2. 輸入模塊 shuru(); 將輸入的兩組長整數(shù)分別通過轉(zhuǎn)換將其轉(zhuǎn)換成所需要的形式存儲(chǔ)到兩個(gè) 鏈表(opr1、opr2)中保存起來。 3. 加法模塊 jiafa(); 將鏈表 opr1、opr2 中的數(shù)據(jù)進(jìn)行加法運(yùn)算,并且二者的將加和保存到鏈 表 oprr 中。 4. 減法模塊 jianfa(); 將鏈表 opr1、opr2 中的數(shù)據(jù)進(jìn)行減法運(yùn)算
5、,并且將二者的差保存到鏈表 oprr 中。 5. 乘法模塊 chengfa(); 將鏈表 opr1、opr2 中的數(shù)據(jù)進(jìn)行乘法運(yùn)算,并且將二者的乘積保存到鏈 表 oprr 中。 6. 除法模塊 chufa(); 將鏈表 opr1、opr2 中的數(shù)據(jù)進(jìn)行加法運(yùn)算,并且將二者的商和余數(shù)分別 保存到鏈表 quti、remand 中。 7. 輸出模塊 shuchu(); 將鏈表 oprr、quti、remand 中的數(shù)據(jù)保存到字符數(shù)組中,并且將字符數(shù)組 中的數(shù)據(jù)輸出到屏幕上。 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 3 3 使用的數(shù)據(jù)結(jié)構(gòu)的描述 3.1 數(shù)據(jù)結(jié)構(gòu)設(shè)計(jì)數(shù)據(jù)結(jié)構(gòu)設(shè)計(jì) 將輸入的兩個(gè)長整數(shù)首先保持到字符
6、數(shù)組中,然后將字符數(shù)組中的字符轉(zhuǎn)換 每四個(gè)一組,利用雙向循環(huán)鏈表來實(shí)現(xiàn)每一組字符的存儲(chǔ),并且高位在前、低位 在后。每個(gè)結(jié)點(diǎn)中只存儲(chǔ)四位十進(jìn)制數(shù)字,即不超過 9999 的非負(fù)整數(shù)。利用兩 個(gè)雙向循環(huán)鏈表分別保持了兩個(gè)非負(fù)長整數(shù)。加法:由低位的結(jié)點(diǎn)開始相加,加 和大于 9999 時(shí),加和除以一萬取余數(shù)保存到新的雙向循環(huán)鏈表結(jié)點(diǎn)中,并且加 和除以一萬取整數(shù)作為進(jìn)位加到下兩個(gè)結(jié)點(diǎn)相加中,依次循環(huán)相加;減法:同加 法有些相似,保證第一個(gè)長整數(shù)不小于于第二個(gè)長整數(shù),結(jié)點(diǎn)相減,不能相減就 相前一結(jié)點(diǎn)借位,差保存到新的雙向循環(huán)鏈表結(jié)點(diǎn)中,依次循環(huán);乘法:由低位 的結(jié)點(diǎn)開始相乘,乘積大于 9999 時(shí),乘積除以
7、一萬取余數(shù)保存到新的雙向循環(huán) 鏈表結(jié)點(diǎn)中,并且乘積除以一萬取整數(shù)作為進(jìn)位加到下兩個(gè)結(jié)點(diǎn)乘積中,依次循 環(huán)相乘;除法:開辟兩個(gè)新的鏈表,保存商數(shù)和差。用第一個(gè)長整數(shù)循環(huán)減去第 二個(gè)長整數(shù),沒減一次計(jì)數(shù)加一,計(jì)數(shù)保存到商數(shù)鏈表中。直到差小于第二個(gè)長 整數(shù)停止循環(huán),最后的計(jì)數(shù)為商值,差值為余數(shù)。 選擇該數(shù)據(jù)結(jié)構(gòu)來完成長整數(shù)的加減乘除運(yùn)算是因?yàn)橐獙?duì)長整數(shù)進(jìn)行運(yùn)算, 需要對(duì)長整數(shù)進(jìn)行存儲(chǔ),所以選擇用鏈表對(duì)長整數(shù)存儲(chǔ),又由于存儲(chǔ)的順序是從 左到右,而運(yùn)算的順序則是從右到左,這樣位了操作方便選擇循環(huán)鏈表,在運(yùn)算 過程中有進(jìn)位和借位的操作,所以最終選擇雙向循環(huán)鏈表的數(shù)據(jù)結(jié)構(gòu)。 3.2 數(shù)據(jù)結(jié)構(gòu)用法說明數(shù)據(jù)結(jié)構(gòu)
8、用法說明 輸入的兩個(gè)長整數(shù)必須為非負(fù)長整數(shù)。加法計(jì)算時(shí)只要保證兩個(gè)數(shù)都為非負(fù) 數(shù)即可,減法、乘法、除法時(shí)需要保證第一個(gè)長整數(shù)大于第二個(gè)長整數(shù)。同時(shí)乘 法、除法計(jì)算時(shí)第二個(gè)數(shù)不能為零,并且輸入的數(shù)一定要合法,最高位不能為零, 否則程序會(huì)提示輸入有誤。 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 4 4 函數(shù)的描述 4.1主要函數(shù)設(shè)計(jì)主要函數(shù)設(shè)計(jì) 1. shuru (); 作用作用:將輸入的兩個(gè)長整數(shù)分別保存到兩個(gè)鏈表中。 2. jiafa(); 作用作用:將兩個(gè)長整數(shù)進(jìn)行加法運(yùn)算,計(jì)算出二者的和。 3. jianfa(); 作用作用:將兩個(gè)長整數(shù)進(jìn)行減法運(yùn)算,計(jì)算出二者的差。 4. chengfa (); 作
9、用作用:將兩個(gè)長整數(shù)進(jìn)行乘法運(yùn)算,計(jì)算出二者的積。 5. chufa(); 作用作用: 將兩個(gè)長整數(shù)進(jìn)行除法運(yùn)算,計(jì)算出二者的商和余數(shù)。 6. shuchu(); 作用作用: 將保存到鏈表中的計(jì)算結(jié)果輸出。 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 5 4.2 主要函數(shù)流程圖主要函數(shù)流程圖 1. kongzhi(): 開始 判斷ch 輸入ch 調(diào) 用 加 法 函 數(shù) 調(diào) 用 減 法 函 數(shù) 調(diào) 用 乘 法 函 數(shù) 調(diào) 用 除 法 函 數(shù) 退 出 程 序 結(jié)束 輸出和輸出差輸出積輸出商 1 2345 圖圖 4.2.14.2.1 控制函數(shù)流程圖控制函數(shù)流程圖 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 6 2. jiafa
10、(); 開始 nodelist p1=opr1,p2=opr2,p3=oprr; 將鏈表opr1、opr2中 的對(duì)應(yīng)結(jié)點(diǎn)中數(shù)據(jù)加 和并加上進(jìn)位 移動(dòng)指針p1、p2 判斷指針p1,p2 是否指向頭指針 若p1沒有指向頭指針 和除以一萬取 整保存為進(jìn)位 和保存到鏈表 oprr中 和大于一萬 是否有進(jìn)位 和除以一萬取余保 存到鏈表oprr中 將鏈表opr1、opr2 中的對(duì)應(yīng)結(jié)點(diǎn)中數(shù) 據(jù)加和 若p2沒有指向頭指針 將opr1中剩余結(jié)點(diǎn) 數(shù)據(jù)保存到oprr中 將opr2中剩余結(jié)點(diǎn) 數(shù)據(jù)保存到oprr中 結(jié)束 yn yn y n y n n y 圖圖 4.2.24.2.2 加法函數(shù)流程圖加法函數(shù)流程圖
11、沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 7 3. jianfa(); 開始 nodelist p1=opr1,p2=opr2,p3=oprr; 將鏈表opr1、opr2 中的對(duì)應(yīng)結(jié)點(diǎn)中數(shù) 據(jù)作差并減去1 移動(dòng)指針p1、p2 判斷指針p2是否 指向頭指針 若p1沒有指向頭指針 差保存到鏈表 oprr中 是否有借位 將鏈表opr1中結(jié)點(diǎn)數(shù)據(jù) 加上一萬后減去opr2中 的對(duì)應(yīng)結(jié)點(diǎn)中數(shù)據(jù) 將opr1中剩余結(jié)點(diǎn) 數(shù)據(jù)保存到oprr中 結(jié)束 y n n y n y 判斷鏈表opr1中結(jié)點(diǎn)的數(shù) 據(jù)大于opr2中對(duì)應(yīng)結(jié)點(diǎn)的 數(shù)據(jù) 將鏈表opr1、opr2 中的對(duì)應(yīng)結(jié)點(diǎn)中數(shù) 據(jù)作差 yn 圖圖 4.2.34.2.3 減法
12、函數(shù)流程圖減法函數(shù)流程圖 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 8 4、chengfa(); 開始 nodelist p1=opr1,p2=opr2,p3=oprr; 將鏈表opr1、opr2中 的結(jié)點(diǎn)中數(shù)據(jù)相乘并 加上進(jìn)位 移動(dòng)指針p1 若p1沒有指向頭指針 和除以一萬取 整保存為進(jìn)位 積保存到鏈表 oprr中 和大于一萬 是否有進(jìn)位 積除以一萬取余保 存到鏈表oprr中 將鏈表opr1、opr2 中的結(jié)點(diǎn)中數(shù)據(jù)相 乘 若p2沒有指向頭指針 結(jié)束 y n y n y n y n n y 是否有進(jìn)位 保存進(jìn)位 進(jìn)位為零 移動(dòng)指針p2 圖圖 4.2.44.2.4 乘法函數(shù)流程圖乘法函數(shù)流程圖 沈陽航空航
13、天大學(xué)課程設(shè)計(jì)報(bào)告 9 5、chufa(); 開始 nodelist p1=opr1,p2=opr2,quti,remand; 將鏈表opr1結(jié)點(diǎn)中數(shù) 據(jù)加一萬后減去opr2 結(jié)點(diǎn)數(shù)據(jù)并減借位 移動(dòng)指針p2 鏈表remand中數(shù)據(jù)是否 大于鏈表opr2中數(shù)據(jù) 是否需要借位 差保存到鏈表remand中 將鏈表opr1、opr2 中的結(jié)點(diǎn)中數(shù)據(jù)相 減 若p2沒有指向頭指針 結(jié)束 y n y n y n 計(jì)數(shù)加一并將計(jì)數(shù) 保存到鏈表quti 圖圖 4.2.54.2.5 除法函數(shù)流程圖除法函數(shù)流程圖 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 10 5 程序測試和運(yùn)行的結(jié)果 5.1 程序測試程序測試 1、程序開始菜
14、單: 圖圖 5.1.15.1.1 菜單圖菜單圖 2、程序退出: 圖圖 5.1.25.1.2 退出程序圖退出程序圖 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 11 5.2 運(yùn)行結(jié)果運(yùn)行結(jié)果 1、加法運(yùn)算: 圖圖 5.2.15.2.1 除法運(yùn)算圖除法運(yùn)算圖 2、減法運(yùn)算: 圖圖 5.2.25.2.2 除法運(yùn)算圖除法運(yùn)算圖 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 12 3、乘法運(yùn)算: 圖圖 5.2.35.2.3 除法運(yùn)算圖除法運(yùn)算圖 4、除法運(yùn)算: 圖圖 5.2.45.2.4 除法運(yùn)算圖除法運(yùn)算圖 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 13 6 參考文獻(xiàn) 1譚浩強(qiáng)著. c 程序設(shè)計(jì)( 第三版). 北京: 清華大學(xué)出版社,2005
15、 2嚴(yán)蔚敏 吳偉明.數(shù)據(jù)結(jié)構(gòu)(c 語言版).北京:清華大學(xué)出版社,2007 3 王裕明.數(shù)據(jù)結(jié)構(gòu)與程序設(shè)計(jì).北京:清華大學(xué)出版社,2010 4 譚浩強(qiáng).c 語言程序設(shè)計(jì)m.北京:清華大學(xué)出版社,2005 5 王敬華 林萍 張清國.c 語言程序設(shè)計(jì)教程m.北京:清華大學(xué)出版社,2005 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 14 附 錄(關(guān)鍵部分程序清單) #include stdafx.h #include #include #include #include #define len sizeof(struct node) #define max 1000 #define ok 1 #define e
16、rror 0 #define overflow -1 #define true 1 #define false 0 typedef int status; typedef struct node int data; struct node *prior,*next; node,*nodelist; int axp(int a,int k) /求指數(shù)函數(shù)值 int r=1; if(k=0) return 1; for(;k0;k-) r=r*a; return r; status zhuanhuan(char str,nodelist int i,k,buffer; k=buffer=0; op
17、rh=(nodelist)malloc(len); oprh-next=oprh; oprh-prior=oprh; for(i=strlen(str)-1;i=0;i-) if(i!=0 | (str0!=- p-prior=oprh; p-next=oprh-next; oprh-next=p; p-data=buffer; buffer=k=0; return ok; status shuru(nodelist printf(nn 請(qǐng)輸入第一個(gè)操作數(shù):n); scanf(%s,str); getchar(); flag=zhuanhuan(str,opr1); while(!flag)
18、printf(整數(shù)輸入有誤,請(qǐng)重新輸入:n); scanf(%s,str); getchar(); flag=zhuanhuan(str,opr1); printf(nn 請(qǐng)輸入第二個(gè)操作數(shù):n); scanf(%s,str); getchar(); flag=zhuanhuan(str,opr2); while(!flag) printf(整數(shù)輸入有誤,請(qǐng)重新輸入:n); 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 16 scanf(%s,str); getchar(); flag=zhuanhuan(str,opr2); return ok; /輸出函數(shù) status shuchu(nodelist o
19、prr,char str) status initbuf(char str); nodelist p; int i,j,num4; if(!oprr) return error; p=oprr; i=j=0; initbuf(str); p=p-next; if(p-next=oprr else while(p!=oprr) num0=p-data/1000; num1=(p-data-num0*1000)/100; num2=(p-data-num0*1000-num1*100)/10; num3=p-data-num0*1000-num1*100-num2*10; while(jnext;
20、 j=0; stri=0; printf(%s,str); printf(n); return ok; status initbuf(char str)/緩沖區(qū)部分初始化函數(shù) 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 17 int i; for(i=0;iprior; p2=opr2-prior; while(p1-prior!=opr1 p2=p2-prior; if(p1-prior!=opr1) return 1; if(p2-prior!=opr2) return -1; return 0; int length(nodelist oprr) /求鏈表長度 int count=0; nodelis
21、t p=oprr-next; while(p!=oprr) count+; p=p-next; return count; status creat(nodelist oprr=(nodelist)malloc(len); p=oprr; while(len0) p-next=(nodelist)malloc(len); p-next-data=?; p-next-prior=p; 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 18 p=p-next; len-; p-next=oprr; oprr-prior=p; return ok; int compare(nodelist opr1,nodelist
22、opr2) /比較 opr1、opr2 絕對(duì)值的大小 nodelist p1,p2; p1=opr1-next; p2=opr2-next; if(cmplinklen(opr1,opr2)=1)/opr1 比較長 return 1; else if(cmplinklen(opr1,opr2)=-1)/opr2 比較長 return -1; else/長度相等的情況 while(p1-data=p2-data p2=p2-next; if(p1-datap2-data) return 1; else if(p1-datadata) return -1; else return 0; /-初始化
23、鏈表函數(shù)- status init(nodelist return ok; /=加法模塊= status jiafa(nodelist opr1,nodelist opr2,nodelist nodelist p1,p2,p3; oprr=(nodelist)malloc(len); 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 19 oprr-next=oprr; oprr-prior=oprr; p1=opr1-prior; p2=opr2-prior; cf=buffer=0; while(p1!=opr1 cf=buffer/10000;/若 buffer 的值大于 9999 則產(chǎn)生進(jìn)位,賦給 cf
24、/將新建結(jié)點(diǎn)插入到頭結(jié)點(diǎn)之后 p3=(nodelist)malloc(len); oprr-next-prior=p3; p3-prior=oprr; p3-next=oprr-next; oprr-next=p3; p3-data=buffer%10000;/應(yīng)該將 buffer 的第四位賦給 p3-data /. p1=p1-prior; p2=p2-prior; while(p1!=opr1) /處理 opr1 鏈的剩余部分 buffer=p1-data+cf; cf=buffer/10000;/若 buffer 的值大于 9999 則產(chǎn)生進(jìn)位,賦給 cf /將新建結(jié)點(diǎn)插入到頭結(jié)點(diǎn)之后
25、p3=(nodelist)malloc(len); oprr-next-prior=p3; p3-prior=oprr; p3-next=oprr-next; oprr-next=p3; p3-data=buffer%10000; /. p1=p1-prior; while(p2!=opr2) /處理 opr2 鏈的剩余部分 buffer=p2-data+cf; cf=buffer/10000;/若 buffer 的值大于 9999 則產(chǎn)生進(jìn)位,賦給 cf /將新建結(jié)點(diǎn)插入到頭結(jié)點(diǎn)之后 p3=(nodelist)malloc(len); oprr-next-prior=p3; p3-prior
26、=oprr; p3-next=oprr-next; 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 20 oprr-next=p3; p3-data=buffer%10000; p2=p2-prior; if(cf) p3=(nodelist)malloc(len); oprr-next-prior=p3; p3-prior=oprr; p3-next=oprr-next; oprr-next=p3; p3-data=cf; return ok; /=減法基本操作= status jianfa(nodelist opr1,nodelist opr2,nodelist nodelist p1,p2,p3,qh,q
27、t,qq; oprr=(nodelist)malloc(len); oprr-next=oprr; oprr-prior=oprr; p1=opr1-prior; p2=opr2-prior; cf=buffer=flag=0; while(p2!=opr2)/opr2 鏈的長度小于等于 opr1 鏈的 if(p1-datadata+cf) buffer=10000+p1-data-(p2-data+cf); cf=1; else buffer=p1-data-(p2-data+cf); cf=0; p3=(nodelist)malloc(len); oprr-next-prior=p3; p
28、3-prior=oprr; p3-next=oprr-next; 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 21 oprr-next=p3; p3-data=buffer; p1=p1-prior; p2=p2-prior; while(p1!=opr1) /處理 opr1 鏈?zhǔn)O碌牟糠?if(p1-datadata-cf; cf=1; else buffer=p1-data-cf; cf=0; p3=(nodelist)malloc(len); oprr-next-prior=p3; p3-prior=oprr; p3-next=oprr-next; oprr-next=p3; p3-data=buff
29、er; p1=p1-prior; /處理鏈表開頭結(jié)點(diǎn)值為 0 的無意義情況,若鏈表本身表示 0,則不做如下處理 p3=oprr-next; while(p3-data=0 flag=1; if(flag) qh=oprr-next;/保存無用結(jié)點(diǎn)的頭尾指針 qt=p3-prior;/為釋放做準(zhǔn)備 oprr-next=p3;/重接 next 鏈 p3-prior=oprr;/重接 prior 鏈 qt-next=null; while(qh!=null) /釋放無用結(jié)點(diǎn) qq=qh; qh=qh-next; 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 22 free(qq); return ok; /=乘法模
30、塊= status chengfa(nodelist opr1,nodelist opr2,nodelist int len,cf; long buffer; ph1=opr1; pt1=ph1-prior; ph2=opr2; pt2=ph2-prior; len=length(opr1)+length(opr2); creat(oprr,len); qq=oprr-next; while(qq!=oprr) qq-data=0; qq=qq-next; buffer=cf=0; p3=oprr-prior; while(pt2!=ph2) pt1=ph1-prior; pt3=p3; wh
31、ile(pt1!=ph1) buffer=pt1-data*pt2-data+pt3-data+cf; cf=(int)buffer/10000; pt3-data=(int)buffer%10000; pt1=pt1-prior; pt3=pt3-prior; pt3-data=cf; cf=0; pt2=pt2-prior; p3=p3-prior; return ok; 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 23 /=除法模塊= /除法子函數(shù) int chufa_zi(nodelist int count,cf,buffer,flag; count=0; while(compare(opr1,o
32、pr2)!=-1)/opr2 鏈長 cf=buffer=0; p1=opr1-prior; p2=opr2-prior; while(p2!=opr2) if(p1-datadata+cf) buffer=10000+p1-data-(p2-data+cf); cf=1; else buffer=p1-data-(p2-data+cf); cf=0; p1-data=buffer; p1=p1-prior; p2=p2-prior; if(p1!=opr1)/處理 opr1 鏈?zhǔn)O碌牟糠?buffer=p1-data-cf; p1-data=buffer; /清頭 0 flag=0; p1=o
33、pr1-next; while(p1-data=0 flag=1; if(flag) 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 24 qh=opr1-next;/保存無用結(jié)點(diǎn)的頭尾指針 qt=p1-prior;/為釋放做準(zhǔn)備 opr1-next=p1;/重接 next 鏈 p1-prior=opr1;/重接 prior 鏈 qt-next=null; while(qh!=null) /釋放無用結(jié)點(diǎn) qq=qh; qh=qh-next; free(qq); count+; return count; /除法函數(shù) status chufa(nodelist opr1,nodelist opr2,nodelis
34、t nodelist q1,q2,pq; if(compare(opr1,opr2)=-1)/除數(shù)比被除數(shù)大 creat(quti,1); quti-next-data=0; quti-next-next=quti; quti-prior=quti-next; remand=opr1; else len_quti=length(opr1)-length(opr2); len_reman=length(opr2); creat(quti,len_quti+1);/開辟商數(shù)鏈 creat(remand,len_reman);/開辟余數(shù)鏈 q1=opr1-next; q2=remand-next;/
35、q2 指向余數(shù)鏈 remand 的下一結(jié)點(diǎn) /初始化 remand 鏈 while(q2!=remand) q2-data=q1-data; q1=q1-next; 沈陽航空航天大學(xué)課程設(shè)計(jì)報(bào)告 25 q2=q2-next; pq=quti-next; q1=q1-prior;/指針退回一步 while(q1!=opr1) buffer=chufa_zi(remand,opr2); pq-data=buffer; if(q1-next!=opr1) remand-prior-next=(nodelist)malloc(len); remand-prior-next-next=remand; r
36、emand-prior-next-prior=remand-prior; remand-prior=remand-prior-next; remand-prior-data=q1-next-data; if(remand-next-data=0 remand-next=remand-next-next; q1=q1-next; pq=pq-next; pq=quti-prior; while(pq-data=?) pq=pq-prior; pq-next=quti; quti-prior=pq; return ok; /=主操作模塊= status kongzhi() nodelist opr1,opr2,oprr,quti,remand; char strmax,ch; opr1=opr2=oprr=quti=remand=null; printf(=n); printf(
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 人力資源行業(yè)招聘與培訓(xùn)經(jīng)驗(yàn)證明書(8篇)
- 電信網(wǎng)絡(luò)優(yōu)化服務(wù)與技術(shù)支持協(xié)議
- 2025年中國綠茶提取物行業(yè)市場深度分析及投資戰(zhàn)略研究報(bào)告
- 辦公樓宇保潔服務(wù)合同
- 老師手中的粉筆寫物8篇
- 綜合物業(yè)服務(wù)保障與監(jiān)督協(xié)議
- 勿忘國恥活動(dòng)方案
- 礦山工人考核管理制度
- pcr設(shè)備管理制度
- 美麗鄉(xiāng)村綠化管理制度
- 部編版七年級(jí)歷史(下)材料論述題專項(xiàng)訓(xùn)練
- 年產(chǎn)1000噸乳酸的生產(chǎn)工藝設(shè)計(jì)
- 博克服裝CAD制版說明操作手冊(cè)(共95頁)
- 南開中學(xué)小卷數(shù)學(xué)模擬試卷(共3頁)
- 光電效應(yīng)測普朗克常數(shù)-實(shí)驗(yàn)報(bào)告
- (完整word版)數(shù)據(jù)模型與決策課程案例分析
- 自制桁架移動(dòng)式操作平臺(tái)施工方案
- 物業(yè)服務(wù)參與校園文化建設(shè)及舉辦大型活動(dòng)配合措施
- 太陽能LED路燈項(xiàng)目實(shí)施方案
- 調(diào)崗調(diào)薪實(shí)操指引PPT課件
- 福清核電廠輻射防護(hù)生產(chǎn)準(zhǔn)備實(shí)踐
評(píng)論
0/150
提交評(píng)論