版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
-.
-數(shù)據(jù)結(jié)構(gòu)
實驗報告專
業(yè)
班
級學(xué)生及學(xué)號課程教學(xué)班號任
課
教
師實驗指導(dǎo)教師實
驗
地
點2015~2016
學(xué)年第2學(xué)期.可修編-
-.
-14驗單元”2各實驗的預(yù)習(xí)分容進實室實的要請按3實驗報告要求書寫整語表清數(shù)和序?qū)嵗砺?lián)實,真析驗出的題現(xiàn),結(jié)驗4參加實驗其中程禁抄5
5.可修編-
-.
-12下”為lnode,并以link,略.可修編-
-.
-i個結(jié)點的指針(函數(shù)。n,n,0n=00,2node*list::address(inti){node*p=head->next;intn=1;while!=i&&p!=NULL){p=p->next;n++;}if(p!=NULL)returnp;elsereturnNULL;}第一組數(shù)據(jù)第二組數(shù)據(jù).可修編-
-.
-ix的n,x=100,in=0,i=5errorcodelist::insert(constinti,constintx){node*p;p=head;intn=1;while!=i&&p!=NULL){p=p->next;n++;}if(i<1||i>length()+1)returnrangeerror;node=newnode;s->data=x;s->next=p->next;p->next=count++;returnsuccess;}i.可修編-
-.nn=0i=5errorcodelist::delete_ele(constinti){node*p;p=head;intn=1;while!=i&&p!=NULL){p=p->next;n++;}if(i1||i>count)returnrangeerror;node*u;u=p->next;p->next=u->next;count--;deleteu;returnsuccess;
-}L(10,20,30,40,50,60,70,80,90,100x25,110和errorcodelist::orderinsert(intx){node*p=head;intn=1;while(p->next!=NULL){if(p->next->data<x)p=p->next;elsebreak;}.可修編-
-.node*u=newnode;u->data=u->next=p->next;p->next=count++;returnsuccess;
-}(1,2,3,4,5,6,7,8,9,10,20,30,40,50,60(10,20,30,40,50,60,70,80,90,100voidseparate(list&A,list&B,list&C){node*LA;node*LB;node*p;node*q;node*u;node*s;LA=A.get_head();LB=B.get_head();q=LA;p=LA->next;s=LB;if(p->data%2==0){u=p;p=p->next;q->next=p;s->next=u;s=s->next;}else{p=p->next;q=q->next;}}和中L3.可修編-
-.
-,3,6,10,15,17,18,20)(1,2,3,4,5,6,7,8,9,10,18,20,30),3,6,10,15,17,18,20),4,5,7,8,9,2,3,4,5,6,7,8,9bingji(listA,listB,list&C){node*LA;node*LB;node*LC;node*a;node*b;LC=C.get_head();LA=A.get_head();LB=B.get_head();a=LA->next;b=LB->next;while(a!=NULL&&b!=NULL){if(a->data<b->data)a=a->next;elseif(a->data>b->data)b=b->next;else{node*c=newnode;c->data=a->data;LC->next=c;LC=c;C.count++;a=a->next;b=b->next;}LC->next=NULL;}CPP文件附加:
數(shù)據(jù)結(jié)構(gòu)試驗一.cpp#include<iostream.h>.可修編-
-.#include<math.h>enumerror_code{success,arrange_error};typedefstructnode{intdata;node*next;}node;classlist{public:intlength()const;node*get_element(intlocate)const;node*locate(constintx)const;error_codecharu(constinti);error_codeinsert(constlocate,constinti);error_codedelete_element(constinti);node*get_head(){returnhead;}voidseparate(list&A,list&B);intbingji(listA,listB,list&C);voidcreate_R();voidlist::show();private:intcount;node*head;node*rear;};head=newnode;head->next=NULL;count=0;}intlist::length()const{node*p=head->next;intcount=0;while(p!=NULL){count++;p=p->next;}returncount;}voidlist::create_R(){intx;請入鏈表的數(shù)值,-1后束創(chuàng)建<<endl;cin>>x;
-.可修編-
-.node*rear=head;while(x!=-1){count++;node*s=newnode;s->data=x;rear->next=s;rear=s;rear->next=NULL;cin>>x;}}node*list::get_element(intlocate)const{if(count==0)return0;else{if(locate<=0||locate>=count)return0;else{node*p=head;intk=0;while(p!=NULL&&k<locate){p=p->next;k++;}returnp;}}}voidlist::show(){node*p=head;while(p!=NULL){cout<<p->data<<"\t";p=p->next;}}error_codelist::insert(constintlocate,constinti){if(count==0){node*s=newnode;s->data=i;s->next=NULL;head->next=s;rear=s;
-.可修編-
-.count=1;returnsuccess;}else{if(locate<1||locate>count+1)returnarrange_error;else{node*p=head;intj=0;while(j!=locate-1&&p!=NULL){p=p->next;j++;}node*s=newnode;s->data=i;s->next=p->next;p->next=s;count++;returnsuccess;}}}error_codelist::charu(constinti){node*p=head;while(p!=NULL&&p->next!=NULL){if(p->data<=i&&i<=p->next->data){node*s=newnode;s->data=i;s->next=p->next;p->next=s;count++;}elsep=p->next;}if(p->next==NULL){node*s=newnode;s->data=i;s->next=NULL;p->next=s;count++;}returnsuccess;}error_codelist::delete_element(consti){node*p=head;j=0;while(j!=i-1&&p!=NULL){p=p->next;j++;}
-.可修編-
-.if(i<1||i>count)returnarrange_error;node*u=newnode;u=p->next;p->next=u->next;deleteu;count--;returnsuccess;}voidseparate(list&A,list&B){node*LA;node*LB;node*p;node*q;node*u;node*s;LA=A.get_head();LB=B.get_head();q=LA;p=LA->next;s=LB;while(p!=NULL){if(p->data%2==0){u=p;p=p->next;q->next=p;s->next=u;s=s->next;}else{p=p->next;q=q->next;}}}voidseparate(list&A,list&B,list&C){node*LA;node*LB;node*p;node*q;node*u;node*s;LA=A.get_head();LB=B.get_head();q=LA;p=LA->next;s=LB;if(p->data%2==0){u=p;p=p->next;q->next=p;s->next=u;s=s->next;}else{p=p->next;q=q->next;}}intlist::bingji(listA,listB,list&C){node*LA;node*LB;node*LC;node*a;node*b;LC=C.get_head();LA=A.get_head();LB=B.get_head();
-.可修編-
-.a=LA->next;b=LB->next;while(a!=NULL&&b!=NULL){if(a->data<b->data)a=a->next;elseif(a->data>b->data)b=b->next;else{node*c=newnode;c->data=a->data;LC->next=c;LC=c;C.count++;a=a->next;b=b->next;}LC->next=NULL;}returnsuccess;}intmain(){intchoice;inti;do{//顯示主菜單
-cout<<"cout<<"
\n";\n";cout<<"
主菜單\n";cout<<"
\n";cout<<"***********************************************"<<endl;cout<<"cout<<"1-創(chuàng)建鏈表2-第i個點指針\n";cout<<"
\n";\n";cout<<"3-在第i節(jié)點前插入一個數(shù)4-刪除鏈表中的第i個點cout<<"cout<<"5-分離鏈表6-公共元\n";cout<<"
\n";\n";cout<<"7-插入一個數(shù)退出\n";cout<<"\n";cout<<"***********************************************"<<endl;cout<<"Enterchoice:";cin>>choice;switch(choice){.可修編-
-.case1:{A.create_R();B.create_R();A.length();B.length();break;}case2:{intk;cout<<"qingshuruk\n";cin>>k;if(A.get_element(k)==NULL)cout<<NULL<<endl;elsecout<<A.get_element(k)->data<<endl;break;}case3:{A.length();inta,b;cout<<"請入a,b\n";cin>>a>>b;A.insert(a,b);A.show();break;}case4:{A.length();inti;請入一個\n";cin>>i;if(i==0||i>A.length())cout<<"NULL\n";elseA.delete_element(i);A.show()
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《計算機組成原理教程》全套教學(xué)課件
- 《Proteus仿真平臺單片機項目式教程》課件 項目5 定時器-2.“9分59秒”定時器
- 2024年業(yè)主委托民宿運營協(xié)議書范文
- 4兄弟分割宅基地協(xié)議書范文
- 0首付買房子欠款協(xié)議書范文
- 職業(yè)技術(shù)學(xué)院木業(yè)產(chǎn)品設(shè)計與制造專業(yè)人才培養(yǎng)方案(三年制)
- 城市軌道交通列車自動控制系統(tǒng)維護 課件 項目三 車站列車自動控制系統(tǒng)維護與檢修
- 音樂創(chuàng)作的基本原理
- 分絲寬幅整經(jīng)機編制說明
- 公司項目部負(fù)責(zé)人安全培訓(xùn)試題帶答案(考試直接用)
- 冀人版三年級(上冊)科學(xué)期中質(zhì)量測試題(二)(含答案)
- 軟籽石榴栽培技術(shù)課件
- 中國農(nóng)業(yè)大學(xué)植物生理學(xué)本科課件 第十一章第六節(jié) 乙烯
- 基于核心素養(yǎng)的高中英語詞匯教學(xué)策略
- 體育公開課教后感,籃球《行進間雙手胸前傳接球》籃球雙手胸前傳接球教案
- TC4鈦合金拉拔工藝探索
- 產(chǎn)品召回演練記錄模板
- (新版)無人機應(yīng)用基礎(chǔ)考試題庫(典型200題)
- 肺癌化療ppt培訓(xùn)課件
- 張弦梁施工方案
- 六年級上冊數(shù)學(xué)課件-3.8 比的基本性質(zhì)丨蘇教版 (共16張PPT)
評論
0/150
提交評論