版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
-.
-数据结构
实验报告专
业
班
级学生及学号课程教学班号任
课
教
师实验指导教师实
验
地
点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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 财险业务建议课件
- 2026年安徽中医药高等专科学校高职单招职业适应性测试参考题库有答案解析
- 基因检测与精准医疗技术
- 2026年湖南工艺美术职业学院单招职业技能考试参考题库带答案解析
- 2026年福建艺术职业学院单招综合素质考试参考题库带答案解析
- 中医与现代医学结合研究
- 护理护理质量改进与提升
- 医院财务状况与预算执行总结
- 医院营养膳食管理人员职业素养
- XX公司年产10万吨铜加工(年产纯铜杆(无氧铜杆)7万吨、2万吨铜排、1万吨铜丝)项目环评报告表
- 2026年湖南邮电职业技术学院单招职业技能考试参考题库附答案详解
- 小学三年级语文上册期末复习知识点总结课件
- 2026年Q1电商店铺运营非遗文化商品上架调研
- 2025-2026学年北师大版高二数学上学期期末常考题之随机事件的条件概率
- 电力部门春节安全生产培训
- 原辅材料领料申请单
- 2023年个税工资表
- 2023新青年新机遇新职业发展趋势白皮书-人民数据研究院
- 管理学原理教材-大学适用
- 变电站一次侧设备温度在线监测系统设计
- GB/T 6579-2007实验室玻璃仪器热冲击和热冲击强度试验方法
评论
0/150
提交评论