




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
-.
-數據結構
實驗報告專
業
班
級學生及學號課程教學班號任
課
教
師實驗指導教師實
驗
地
點2015~2016
學年第2學期.可修編-
-.
-14驗單元”2各實驗的預習分容進實室實的要請按3實驗報告要求書寫整語表清數和序實理聯實,真析驗出的題現,結驗4參加實驗其中程禁抄5
5.可修編-
-.
-12下”為lnode,并以link,略.可修編-
-.
-i個結點的指針(函數。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;}第一組數據第二組數據.可修編-
-.
-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文件附加:
數據結構試驗一.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;請入鏈表的數值,-1后束創建<<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-創建鏈表2-第i個點指針\n";cout<<"
\n";\n";cout<<"3-在第i節點前插入一個數4-刪除鏈表中的第i個點cout<<"cout<<"5-分離鏈表6-公共元\n";cout<<"
\n";\n";cout<<"7-插入一個數退出\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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國EVA鞋材數據監測報告
- 2025年中國2.9-二甲基喹吖啶酮數據監測研究報告
- 2025至2030年中國龍韻石磚市場分析及競爭策略研究報告
- 2025至2030年中國陶瓷棺市場分析及競爭策略研究報告
- 2025至2030年中國鉛合金產品市場分析及競爭策略研究報告
- 2025至2030年中國花泥樹脂市場分析及競爭策略研究報告
- 2025至2030年中國線控工程車市場分析及競爭策略研究報告
- 2025至2030年中國矯形胸托市場分析及競爭策略研究報告
- 2025至2030年中國瓦楞針市場分析及競爭策略研究報告
- 2025至2030年中國滑片泵市場分析及競爭策略研究報告
- 一級圓柱齒輪減速器的設計計算22001文檔
- 第19章一次函數-一次函數專題數形結合一一次函數與45°角模型講義人教版數學八年級下冊
- 2023年四川省宜賓市敘州區數學六年級第二學期期末考試模擬試題含解析
- 船舶柴油機綜合題庫
- 房屋抵押合同范本模板
- 近期金融行業風險案例匯編
- 幼兒園警察職業介紹課件
- 棉印染清潔生產審核報告
- 板鞋競速競賽規則
- 滅火器維修與報廢規程
- 皮膚病的臨床取材及送檢指南-修訂版
評論
0/150
提交評論