資源描述:
《上機(jī)實(shí)驗(yàn)報(bào)告(二)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、“數(shù)據(jù)結(jié)構(gòu)和算法II”課程實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)名稱:線性表的綜合應(yīng)用班級(jí)_14知識(shí)產(chǎn)權(quán)1班_姓名學(xué)號(hào)_實(shí)驗(yàn)日期:2015/04/08實(shí)驗(yàn)機(jī)時(shí):2學(xué)時(shí)實(shí)驗(yàn)成績(jī):-------------------------------------------------------------------------------實(shí)驗(yàn)?zāi)康模赫莆枕樞虮砗玩湵淼母拍?,學(xué)會(huì)對(duì)問題進(jìn)行分析,選擇恰當(dāng)?shù)倪壿嫿Y(jié)構(gòu)和物理結(jié)構(gòu)加深對(duì)順序表和鏈表的理解,培養(yǎng)解決實(shí)際問題的編程能力實(shí)驗(yàn)內(nèi)容:實(shí)現(xiàn)一元稀疏多項(xiàng)式的表示及基本操作(建立、銷毀、輸出、加法、減法、乘法等操作);一.實(shí)驗(yàn)內(nèi)容:實(shí)現(xiàn)一元稀疏多
2、項(xiàng)式的表示及基本操作(建立,銷毀,輸出,加法,減法,求項(xiàng)數(shù)等操作)一元多項(xiàng)式一定要包含系數(shù)項(xiàng)和指數(shù)項(xiàng)的描述,對(duì)一元多項(xiàng)式的基本運(yùn)算,可應(yīng)用兩個(gè)有序鏈表合并的思想進(jìn)行二.程序及注釋:#include"stdio.h"#include"string.h"#include"stdlib.h"#include"ctype.h"typedefstructnode//定義結(jié)點(diǎn){chardata[10];//結(jié)點(diǎn)的數(shù)據(jù)域?yàn)樽址畇tructnode*next;//結(jié)點(diǎn)的指針域}ListNode;typedefListNode*LinkList;//自定義LinkLis
3、t單鏈表類型LinkListCreatListR1();//函數(shù),用尾插入法建立帶頭結(jié)點(diǎn)的單鏈表LinkListCreatList(void);//函數(shù),用頭插入法建立帶頭結(jié)點(diǎn)的單鏈表ListNode*LocateNode();//函數(shù),按值查找結(jié)點(diǎn)voidDeleteList();//函數(shù),刪除指定值的結(jié)點(diǎn)voidprintlist();//函數(shù),打印鏈表中的所有值otherstaffoftheCentre.Duringthewar,ZhuwastransferredbacktoJiangxi,andDirectorofthenewOfficeinJi
4、ngdezhen,JiangxiCommitteeSecretary.Startingin1939servedasrecorderoftheWestNorthOrganization,SecretaryoftheSpecialCommitteeAfterthevictoryofthelongMarch,hehasbeentheNorthwestOfficeoftheFederationofStateenterprisesMinister,ShenmufuguSARmissions,DirectorofNingxiaCountypartyCommittee
5、SecretaryandrecorderoftheCountypartyCommitteeSecretary,MinistersandvoidDeleteAll();//函數(shù),刪除所有結(jié)點(diǎn),釋放內(nèi)存ListNode*AddNode();//修改程序:增加節(jié)點(diǎn)。用頭插法,返回頭指針//==========主函數(shù)==============voidmain(){charch[10],num[5];LinkListhead;head=CreatList();//用頭插入法建立單鏈表,返回頭指針printlist(head);//遍歷鏈表輸出其值printf("
6、Deletenode(y/n):");//輸入"y"或"n"去選擇是否刪除結(jié)點(diǎn)scanf("%s",num);if(strcmp(num,"y")==0
7、
8、strcmp(num,"Y")==0){printf("PleaseinputDelete_data:");scanf("%s",ch);//輸入要?jiǎng)h除的字符串DeleteList(head,ch);printlist(head);}printf("Addnode?(y/n):");//輸入"y"或"n"去選擇是否增加結(jié)點(diǎn)scanf("%s",num);if(strcmp(num,"y")==0
9、
10、s
11、trcmp(num,"Y")==0){head=AddNode(head);}printlist(head);DeleteAll(head);//刪除所有結(jié)點(diǎn),釋放內(nèi)存}//==========用尾插入法建立帶頭結(jié)點(diǎn)的單鏈表===========LinkListCreatListR1(void){charch[10];LinkListhead=(LinkList)malloc(sizeof(ListNode));//生成頭結(jié)點(diǎn)ListNode*s,*r,*pp;r=head;r->next=NULL;printf("Input#toend");//輸入"
12、#"代表輸入結(jié)束printf("PleaseinputNode_data:"