




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
-.
-数据结构
实验报告专
业
班
级学生及学号课程教学班号任
课
教
师实验指导教师实
验
地
点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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 西藏育苗大棚管理办法
- 设计团队薪酬管理办法
- 诸城民政殡葬管理办法
- 财务如何资产管理办法
- 财务记账软件管理办法
- 财政垫付资金管理办法
- 财政票据管理办法心得
- 账户共管资金管理办法
- 资金市场风险管理办法
- 资金智能调度管理办法
- 近期金融行业风险案例汇编
- 棉印染清洁生产审核报告
- 板鞋竞速竞赛规则
- 灭火器维修与报废规程
- JJF 1183-2007温度变送器校准规范
- GB/T 41051-2021全断面隧道掘进机岩石隧道掘进机安全要求
- GB/T 37787-2019金属材料显微疏松的测定荧光法
- Unit2 Section B(1a-1e)作业设计教案 人教版英语八年级上册
- GB 6722-2014爆破安全规程
- GA/T 1169-2014警用电子封控设备技术规范
- 校企合作项目立项申请表(模板)
评论
0/150
提交评论