數(shù)據(jù)結(jié)構(gòu):鏈表的應(yīng)用_第1頁
數(shù)據(jù)結(jié)構(gòu):鏈表的應(yīng)用_第2頁
數(shù)據(jù)結(jié)構(gòu):鏈表的應(yīng)用_第3頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、實(shí)驗(yàn):鏈表的應(yīng)用-求兩個(gè)一元多項(xiàng)式之和班級:計(jì)科114 學(xué)號:20111515415 姓名:顧晴晴一 實(shí)驗(yàn)?zāi)康模菏煜ゆ湵淼幕静僮?,掌握用線性鏈表表示多項(xiàng)式加法運(yùn)算的方法。二.實(shí)驗(yàn)內(nèi)容:1. 實(shí)驗(yàn)要求用單鏈表存儲一元多項(xiàng)式,將兩個(gè)存儲一元多項(xiàng)式的單鏈表相加產(chǎn)生結(jié) 果單鏈表。2. 源程序如下#include<stdio. h>#includestdlib h>typedef struct Listnodeint xishu;struct Listnode *next;int mi;* Pnode;Pnode init(int t)Pnode phead = (Pnode)mal

2、loc(sizeof(Pnode):辻(NULL 二二 phead)exit (-1);Pnode ptail = phead;ptdi1-next = NULL;int a, b;for(int i = 0; i < t; i+)Pnode pnew = (Pnode)malloc(sizeof(Pnode):if(NULL = pnew) exit (-1);printff輸入該項(xiàng)的系數(shù):");scanf(”%d", &a);pnew->xishu = a;printf C輸入幕數(shù):”);scanf ("%d: &b);pnew-&

3、gt;mi = b;ptail>next = pnew;pnew->next = NULL;ptail = pnew;return phead;Pnode jia (Pnode pl,Pnode p2)Pnode phead = (Pnode)malloc(sizeof(Pnode);辻(NULL 二二 phead) exit (T);Pnode ptail = phead;ptail->next = NULL;pl = pl-next;p2 = p2-next;while(pl!= NULL && p2 二二 NULL) (pl 二二 NULL &&

4、amp; p2 !=NULL) pl != NULL p2 != NULL)辻(pl = NULL && p2 != NULL)Pnode pnew = (Pnode)malloc(sizeof(Pnode): if(NULL = pnew) exit (T);pnew->mi = p2->mi;pnew->xishu = p2-xishu;ptail->next = pnew;pnew->next = NULL;ptail = pnew;p2 = p2-next;else 辻(pl '= NULL && p2 二二 NUL

5、L)Pnode pnew = (Pnode)malloc(sizeof(Pnode); if(NULL = pnew) exit (T);pnew->mi = pl->mi;pnew->xishu = pl->xishu;ptdi1-next = pnew;pnew->next = NULL;ptail = pnew;pl = pl->next;else if (pl->mi = p2->mi )Pnode pnew = (Pnode)malloc(sizeof(Pnode): if(NULL = pnew)exit(-1);pnew->x

6、ishu = pl-xishu + p2-xishu;pnew->mi = pl-mi;ptail->next 二 pnew;pnew->next = NULL;ptail = pnew;pl = pl-next;p2 = p2->next;else if(pl->mi > p2->mi )Pnode pnew = (Pnode)malloc(sizeof(Pnode);if(NULL = pnew) exit (-1);pnew->mi = pl-mi;pnew->xishu = pl-xishu;ptail->next 二 pne

7、w;pnew->next = NULL;ptail = pnew;pl = pl-next;else if(pl->mi < p2->mi )Pnode pnew = (Pnode)malloc(sizeof(Pnode):if(NULL = pnew) exit (-1); pnew->mi = p2->mi;pnew->xishu = p2-xishu;ptail->next 二 pnew;pnew->next = NULL;ptail = pnew;p2 = p2-next;return phead;void print(Pnode

8、phead , char x )char y 二'Pnode p = phead>next;printff兩個(gè)一元多項(xiàng)式的和=“);while(NULL != p)if(p->mi = 0)printf (“%d ",p-xishu);elseprintfp->xishu);printf(”%c", x);printf("%d “, p->mi);printf C%c ”, y);p = p->next;printf("n");int main(void)Pnode pl,p2;int a, b;char

9、x;printf ("輸入未知字母(如x, y, z等):");scanf&x);printfC輸入第一個(gè)多項(xiàng)式的項(xiàng)數(shù):");scanf&d);pl = init(a);printfr輸入第二個(gè)多項(xiàng)式的項(xiàng)數(shù):");scanf(”%d", &b);p2 二 init(b);print (jia(pl, p2), x);return 0;3.程序調(diào)試過程記錄:1.第一次調(diào)試:配置:mingwS - CUI Debug,編譯器類型:MinGW-檢查文件依賴性 正在編譯 C: UsersAdministratorDocument

10、sC-FreeProjects未命名 2. cpp.Errorj C:UsersAdministratorDocumentsC-FreeProjectsi 2 cpp:53: error: P2J was not declared in this scopeErrorj C:UsersAdministratorDocumentsC-FreeProjectsi 2 cpp:53: error: Pl was not declared in this scopeErrorj C:UsersAdministratorDocumentsC-FreeProjectsi 2 cpp:53: error:

11、expectedbefore ' !' tokenErrorZ C:UsersAdministratorDocumentsC-FreeProjects 2. cpp:53: error: expected primary-expression before '二'tokenErrorj C:UsersAdministratorDocumentsC-FreeProjectsi 2 cpp:53: error: expected before tokenErrorj C:UsersAdministratorDocumentsC-FreeProjectsi 2 cpp

12、:55: error: stray '163 in programErrorj C:UsersAdministratorDocumentsC-FreeProjectsi 2 cpp:55: error: stray '161 in programErrorZC:UsersAdministratorDocumentsC-FreeProjects 未 命 名2.cpp:118: error: a function-definition is not allowed here before tokenErrorC:UsersAdministratoiADocumentsCFreePr

13、ojects2.cpp:121: error: stray '163 in programErrorC:UsersAdminis tratorDocumentsC-F:reeP:rojects2.cpp:121: error: stray ,187, in program未命名未命名未命名ErrorC:UsersAdministratorDocumentsC-FreeProjects2. cpp:148: error: 'a was not declared in this scopeErrorC:UsersAdministratorDocumentsC-FreeProject

14、s2.cpp:151: error:was not declared in this scopeError! C:UsersAdministratorDocumentsC-FreeProjects2.cpp:154: error: 'x was not declared in this scope ErrorC:UsersAdministratorDocumentsC-FreeProjects2. cpp:154: error: 'print1 was not declared in this scope未命未命未命未命Warnings C:UsersAdministrator

15、DocumentsC-FreeProjects 未 命名名名名名ErrorZ C:UsersAdministratorDocumentsC-FreeProjects 2cpp:140: error: a function-definition is not allowed here before token2cpp:156:2: warning: no newline at end of file構(gòu)建中止未命名2: 15個(gè)錯(cuò)誤,1個(gè)警告2.最后一次調(diào)試配置:mingwS - CUI Debug,編譯器類型:MinGW-檢查文件依賴性.完成構(gòu)建未命名2: 0個(gè)錯(cuò)誤,0個(gè)警告生成 C: UsersAdministratorDocumentsC-FreeProjects未命名 2. exe4.實(shí)驗(yàn)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論