數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告—一元多項(xiàng)式加法、減法、乘法運(yùn)算的實(shí)現(xiàn)_第1頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告—一元多項(xiàng)式加法、減法、乘法運(yùn)算的實(shí)現(xiàn)_第2頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告—一元多項(xiàng)式加法、減法、乘法運(yùn)算的實(shí)現(xiàn)_第3頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告—一元多項(xiàng)式加法、減法、乘法運(yùn)算的實(shí)現(xiàn)_第4頁(yè)
數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告—一元多項(xiàng)式加法、減法、乘法運(yùn)算的實(shí)現(xiàn)_第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、-PAGE . z1.一元多項(xiàng)式加法、減法、乘法運(yùn)算的實(shí)現(xiàn)1.1設(shè)計(jì)容及要求1)設(shè)計(jì)容1使用順序存儲(chǔ)構(gòu)造實(shí)現(xiàn)多項(xiàng)式加、減、乘運(yùn)算。例如:,求和結(jié)果:2使用鏈?zhǔn)酱鎯?chǔ)構(gòu)造實(shí)現(xiàn)多項(xiàng)式加、減、乘運(yùn)算,求和結(jié)果:2設(shè)計(jì)要求1用C語(yǔ)言編程實(shí)現(xiàn)上述實(shí)驗(yàn)容中的構(gòu)造定義和算法。2要有main()函數(shù),并且在main()函數(shù)中使用檢測(cè)數(shù)據(jù)調(diào)用上述算法。3用switch語(yǔ)句設(shè)計(jì)如下選擇式菜單。 *數(shù)據(jù)構(gòu)造綜合性實(shí)驗(yàn)* *一、多項(xiàng)式的加法、減法、乘法運(yùn)算* * 1.多項(xiàng)式創(chuàng)立 * * 2.多項(xiàng)式相加 * * 3.多項(xiàng)式相減 * 4.多項(xiàng)式相乘 * 5.清空多項(xiàng)式 * 0.退出系統(tǒng) * 請(qǐng)選擇05 *請(qǐng)選擇0-5:1.

2、2數(shù)據(jù)構(gòu)造設(shè)計(jì)根據(jù)下面給出的存儲(chǔ)構(gòu)造定義:#define MA*SIZE 20 /定義線性表最大容量 /定義多項(xiàng)式項(xiàng)數(shù)據(jù)類型typedef structfloat coef; /系數(shù)int e*pn; /指數(shù) term,elemType;typedef structterm termsMA*SIZE; /線性表中數(shù)組元素int last; /指向線性表中最后一個(gè)元素位置 SeqList;typedef SeqList polynomial;1.3根本操作函數(shù)說明polynomial*Init_Polynomial();/初始化空的多項(xiàng)式int PloynStatus(polynomial*p)

3、/判斷多項(xiàng)式的狀態(tài)int Location_Element(polynomial*p,term *)在多項(xiàng)式p中查找與*項(xiàng)指數(shù)一樣的項(xiàng)是否存在int Insert_ElementByOrder(polynomial*p,term *)/在多項(xiàng)式p中插入一個(gè)指數(shù)項(xiàng)*int CreatePolyn(polynomial*P,int m)/輸入m項(xiàng)系數(shù)和指數(shù),建立表示一元多項(xiàng)式的有序表pchar pare(term term1,term term2)/比擬指數(shù)項(xiàng)term1和指數(shù)項(xiàng)term2polynomial*addPloyn(polynomial*p1,polynomial*p2)/將多項(xiàng)式p1和

4、多項(xiàng)式p2相加,生成一個(gè)新的多項(xiàng)式polynomial*subStractPloyn(polynomial*p1,polynomial*p2)/多項(xiàng)式p1和多項(xiàng)式p2相減,生成一個(gè)新的多項(xiàng)式polynomial*mulitPloyn(polynomial*p1,polynomial*p2)/多項(xiàng)式p1和多項(xiàng)式p2相乘,生成一個(gè)新的多項(xiàng)式void printPloyn(polynomial*p)/輸出在順序存儲(chǔ)構(gòu)造的多項(xiàng)式p1.4程序源代碼#include#include#include#define NULL 0#define MA*SIZE 20typedef structfloat coe

5、f;int e*pn;term,elemType;typedef structterm termsMA*SIZE;int last;SeqList;typedef SeqList polynomial;void printPloyn(polynomial*p);int PloynStatus(polynomial*p)if(p=NULL)return -1;else if(p-last=-1)return 0;elsereturn 1;polynomial*Init_Polynomial()polynomial*P;P=new polynomial;if(P!=NULL)P-last=-1;r

6、eturn P;elsereturn NULL;void Reset_Polynomial(polynomial*p)if(PloynStatus(p)=1)p-last=-1;int Location_Element(polynomial*p,term *)int i=0;if(PloynStatus(p)=-1)return 0;while(ilast & p-termsi.e*pn!=*.e*pn)i+;if(ip-last)return 0;elsereturn 1;int Insert_ElementByOrder(polynomial*p,term *)int j;if(Ployn

7、Status(p)=-1)return 0;if(p-last=MA*SIZE-1)coutThe polym is full!last;while(p-termsj.e*pn=0) p-termsj+1=p-termsj; j-; p-termsj+1=*;p-last+;return 1;int CreatePolyn(polynomial*P,int m)float coef;int e*pn;term *;if(PloynStatus(P)=-1)return 0;if(mMA*SIZE)printf(順序表溢出n);return 0;elseprintf(請(qǐng)依次輸入%d對(duì)系數(shù)和指數(shù).

8、n,m);for(int i=0;iterm2.e*pn)return;else if(term1.e*pnterm2.e*pn)return;elsereturn=;polynomial*addPloyn(polynomial*p1,polynomial*p2)int i,j,k;i=0;j=0;k=0;if(PloynStatus(p1)=-1)|(PloynStatus(p2)=-1)return NULL;polynomial*p3=Init_Polynomial();while(ilast & jlast)switch(pare(p1-termsi,p2-termsj)case:p3

9、-termsk+=p1-termsi+;p3-last+;break;casetermsk+=p2-termsj+;p3-last+;break;case=:if(p1-termsi.coef+p2-termsj.coef!=0)p3-termsk.coef=p1-termsi.coef+p2-termsj.coef;p3-termsk.e*pn=p1-termsi.e*pn;k+;p3-last+;i+;j+;while(ilast)p3-termsk+=p1-termsi+;p3-last+;return p3;polynomial*subStractPloyn(polynomial*p1

10、,polynomial*p2)int i;i=0;if(PloynStatus(p1)!=1)|(PloynStatus(p2)!=1)return NULL;polynomial*p3=Init_Polynomial();p3-last=p2-last;for(i=0;ilast;i+)p3-termsi.coef=-p2-termsi.coef;p3-termsi.e*pn=p2-termsi.e*pn;p3=addPloyn(p1,p3);return p3;polynomial*mulitPloyn(polynomial*p1,polynomial*p2)int i;int j;int

11、 k;i=0;if(PloynStatus(p1)!=1)|(PloynStatus(p2)!=1)return NULL;polynomial*p3=Init_Polynomial();polynomial*p=new polynomial*p2-last+1;for(i=0;ilast;i+)for(k=0;klast;k+)pk=Init_Polynomial();pk-last=p1-last;for(j=0;jlast;j+)pk-termsj.coef=p1-termsj.coef*p2-termsk.coef;pk-termsj.e*pn=p1-termsj.e*pn+p2-te

12、rmsk.e*pn;p3=addPloyn(p3,pk);return p3;void printPloyn(polynomial*p)int i;for(i=0;ilast;i+)if(p-termsi.coef0 & i0)cout+termsi.coef;elsecouttermsi.coef;cout*termsi.e*pn;coutendl;void menu()couttt*數(shù)據(jù)構(gòu)造綜合性實(shí)驗(yàn)*endl;couttt*一、多項(xiàng)式的加、減、乘法運(yùn)算*endl;couttt* 1.多項(xiàng)式創(chuàng)立 *endl;couttt* 2.多項(xiàng)式相加 *endl;couttt* 3.多項(xiàng)式相減 *en

13、dl;couttt* 4.多項(xiàng)式相乘 *endl;couttt* 5.清空多項(xiàng)式 *endl;couttt* 0.退出系統(tǒng) *endl;couttt* 請(qǐng)選擇(0-5) *endl;couttt*endl;void main()int sel;polynomial*p1=NULL;polynomial*p2=NULL;polynomial*p3=NULL;while(1)menu();coutsel;switch(sel)case 1:p1=Init_Polynomial();p2=Init_Polynomial();int m;printf(請(qǐng)輸入第一個(gè)多項(xiàng)式的項(xiàng)數(shù):n);scanf(%d,

14、&m);CreatePolyn(p1,m);printf(第一個(gè)多項(xiàng)式的表達(dá)式為p1=);printPloyn(p1);printf(請(qǐng)輸入第二個(gè)多項(xiàng)式的項(xiàng)數(shù):n);scanf(%d,&m);CreatePolyn(p2,m);printf(第二個(gè)多項(xiàng)式的表達(dá)式為p2=);printPloyn(p2);break;case 2:printf(p1+p2=);if(p3=subStractPloyn(p1,p2)!=NULL)printPloyn(p3);break;case 3:printf(np1-p2=);if(p3=subStractPloyn(p1,p2)!=NULL)printPlo

15、yn(p3);break;case 4:printf(np1*p2=);if(p3=mulitPloyn(p1,p2)!=NULL)printPloyn(p3);case 5:Reset_Polynomial(p1);Reset_Polynomial(p2);Reset_Polynomial(p3);break;case 0:return;return;1.5程序執(zhí)行結(jié)果2.迷宮問題實(shí)現(xiàn)2.1設(shè)計(jì)容及要求1設(shè)計(jì)容以一個(gè)m*n的長(zhǎng)方陣表示迷宮,0和1分別表示迷宮中的通路和障礙。設(shè)計(jì)一個(gè)程序,對(duì)任意設(shè)定的迷宮,求出一條從入口到出口的道路,或得出沒有通路的結(jié)論。2)設(shè)計(jì)要求1用C語(yǔ)言編程實(shí)現(xiàn)上述實(shí)驗(yàn)

16、容中的構(gòu)造定義和算法;2要有main()函數(shù),并且在main()函數(shù)中使用檢測(cè)數(shù)據(jù)調(diào)用上述算法;2.2數(shù)據(jù)構(gòu)造設(shè)計(jì)根據(jù)以上問題給出存儲(chǔ)構(gòu)造定義:typedef struct /定義坐標(biāo)int *;int y;item; /定義坐標(biāo)和方向typedef structint *;int y;int d;dataType; /定義順序棧的類型定義typedef structdataType dataMA*LEN;int top;SeqStack;item move8; /8鄰域試探方向數(shù)組int mazeM+2N+2=1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1

17、,1,0,1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,1,1,1,0,1,1,1,0,1,1,1,1,1,1,0,0,1,1,0,0,0,1,1,0,1,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,; /定義迷宮數(shù)組,0表示有路徑,1表示不存在路徑2.3根本操作函數(shù)說明void print_Path(SeqStack*s);/輸出迷宮路線SeqStack*InitSeqStack()/該函數(shù)初始化一個(gè)空棧,并返回指向該棧的存儲(chǔ)單元首地址int Push(SeqStack*s,dataType *)/將元素*入棧s,假設(shè)入棧成功返回結(jié)果1;否則返回0int

18、 StackEmpty(SeqStack*s)/該函數(shù)判斷棧是否為空,假設(shè)??辗祷亟Y(jié)果1;否則返回0int Pop(SeqStack*s,dataType*)/將棧頂元素出棧,放入*所指向的存儲(chǔ)單元中,假設(shè)出棧返回結(jié)果1;否則返回0void init_move(item move8)/初始化8鄰域方向int find_Path(int mazeM+2N+2,item move8)/在迷宮maze二維數(shù)組中按move的8鄰域方向探測(cè)迷宮路線,存在返回1,否則返回0void print_Path(SeqStack*s)/輸出棧s中所有迷宮路徑2.4程序源代碼#include#include#def

19、ine M 6#define N 8#define MA*LEN 100typedef structint *;int y;item;typedef structint *;int y;int d;dataType;typedef structdataType dataMA*LEN;int top;SeqStack;item move8;int mazeM+2N+2=1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,1,1,1,0,1,1,1,0,1,1,1,1,1,1,0,0,1,1,0,0

20、,0,1,1,0,1,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,;void print_Path(SeqStack*s);SeqStack*InitSeqStack()SeqStack*s;s=new SeqStack;s-top=-1;return s;int Push(SeqStack*s,dataType *)if(s-top=MA*LEN-1)return 0;elses-top+;s-datas-top=*;return 1;int StackEmpty(SeqStack*s)if(s-top=-1)return 1;elsereturn 0;int Pop

21、(SeqStack*s,dataType*)if(StackEmpty(s)return 0;else*=s-datas-top;s-top-;return 1;void init_move(item move8)move0.*=0;move0.y=1;move1.*=1;move1.y=1;move2.*=1;move2.y=0;move3.*=1;move3.y=-1;move4.*=0;move4.y=-1;move5.*=-1;move5.y=-1;move6.*=-1;move6.y=0;move7.*=-1;move7.y=1;void printS(dataType temp)i

22、nt static i=0;printf(第%d次入棧元素為:,+i);printf(%d,%d)%dn,temp.*,temp.y,temp.d);int find_Path(int mazeM+2N+2,item move8)SeqStack*s=InitSeqStack();dataType temp;int *,y,d,i,j;temp.*=1;temp.y=1;temp.d=-1;Push(s,temp); while(!StackEmpty(s)Pop(s,&temp);*=temp.*;y=temp.y;d=temp.d+1;while(d8)i=*+moved.*;j=y+moved.y;if(mazeij=0)temp.*=*;temp.y=y;temp.d=d;Push(s,temp);printS(temp);*=i;y=j;maze*y=-1;if(*=M & y=N)print_Path(s);return 1;elsed=0;elsed+;return 0;void print_Path(SeqStack*s)pr

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論