版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
-.
-数据结构
实验报告专
业
班
级学生及学号课程教学班号任
课
教
师实验指导教师实
验
地
点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山东青岛市教育局直属学校招聘教师100人备考题库含答案详解(研优卷)
- 2026江西寻乌县公安局招聘留置看护队员3人备考题库附答案详解(黄金题型)
- 小学信息科技川教版(新教材)四年级下册每课教学反思
- 2026安徽芜湖市人才发展集团代招聘7人备考题库(三)附答案详解(夺分金卷)
- 2026江苏南京中医药大学招聘1人备考题库含答案详解(培优a卷)
- 2026重庆市万州区余家镇人民政府招聘非全日制公益性岗位8人备考题库及一套完整答案详解
- 2026宁麓置地(宁波)有限公司招聘7人备考题库及答案详解(基础+提升)
- 2026天津滨海美都嘉宾轩投资管理有限责任公司社会招聘总经理的1人备考题库附答案详解(b卷)
- 2026江苏盐城市大丰区疾病预防控制中心招聘劳务派遣1人备考题库及答案详解(有一套)
- 2026福建福州新区(长乐区)卫健教育系统招聘医学类专业人员60人备考题库含答案详解(模拟题)
- GA 1817.1-2026学校反恐怖防范要求第1部分:普通高等学校
- 2026云南临沧市文化旅游产业发展集团有限公司招聘26人笔试备考试题及答案解析
- (2026年课件合集)人教版二年级数学下册全册教案(教学设计)
- 通信工程监理规范
- 2025年设计学博士招生面试题库及详细答案
- 2026校招:中国出口信用保险笔试题及答案
- 2025年广西机场管理集团有限责任公司第一批次招聘106人笔试参考题库附带答案详解
- DB44-T 2814-2026 城镇燃气用户端设施安全技术标准
- 台军知识课件
- 《全国应急广播体系建设总体规划》
- 动物免疫学抗感染免疫
评论
0/150
提交评论