合肥工业大学数据结构试验一实验报告文档格式.docx
- 文档编号:14105426
- 上传时间:2022-10-18
- 格式:DOCX
- 页数:19
- 大小:51.03KB
合肥工业大学数据结构试验一实验报告文档格式.docx
《合肥工业大学数据结构试验一实验报告文档格式.docx》由会员分享,可在线阅读,更多相关《合肥工业大学数据结构试验一实验报告文档格式.docx(19页珍藏版)》请在冰豆网上搜索。
一、试验目和要求∶
(1)了解线性表链式存放结构。
(2)熟练掌握动态链表结构及相关算法设计。
(3)依据具体问题需要,设计出合理表示数据链表结构,设计相关算法。
二、试验任务∶
说明1:
此次试验中链表结构均为带头结点单链表。
说明2:
为使试验程序简练直观,下面部分试验程序中将所需要函数以调用库函数形式给出,并假设将库函数放在程序文件“linklist.h”中,同时假设该库函数文件中定义了链表结构中指针类型为link,结点类型为node,并定义了部分常见运算。
比如构建链表、以某种方法显示链表、从文件中读入一个链表、跟踪访问链表结点等。
各运算名称较为直观,并有对应注释,所以易于了解和实现。
三、试验准备方案,包含以下内容:
(硬件类试验:
试验原理、试验线路、设计方案等)
(软件类试验:
所采取关键方法、框架或步骤图及程序清单)
试验准备方案:
构建库函数:
定义了链表结构中指针类型为link,结点类型为node,并定义了部分常见运算,如构建链表,显示链表,读取链表,访问链表等;
步骤:
略
试验内容
一、试验用仪器、设备:
个人计算机
C-free5.0
二、试验内容与步骤(过程及数据统计):
<
1>
求链表中第i个结点指针(函数),若不存在,则返回NULL。
试验测试数据基础要求:
第一组数据:
链表长度n≥10,i分别为5,n,0,n+1,n+2
第二组数据:
链表长度n=0,i分别为0,2
node*list:
:
address(inti)
{
node*p=head->
next;
intn=1;
while(n!
=i&
&
p!
=NULL)
{
p=p->
n++;
}
if(p!
=NULL)returnp;
elsereturnNULL;
}
第一组数据
第二组数据
2>
在第i个结点前插入值为x结点。
链表长度n≥10,x=100,i分别为5,n,n+1,0,1,n+2
链表长度n=0,x=100,i=5
errorcodelist:
insert(constinti,constintx)
node*p;
p=head;
if(i<
1||i>
length()+1)returnrangeerror;
node*s=newnode;
s->
data=x;
next=p->
p->
next=s;
count++;
returnsuccess;
3>
删除链表中第i个元素结点。
链表长度n≥10,i分别为5,n,1,n+1,0
链表长度n=0,i=5
delete_ele(constinti)
if(i<
1||i>
count)returnrangeerror;
node*u;
u=p->
next=u->
count--;
deleteu;
4>
在一个递增有序链表L中插入一个值为x元素,并保持其递增有序特征。
链表元素为(10,20,30,40,50,60,70,80,90,100),
x分别为25,85,110和8
orderinsert(intx)
node*p=head;
while(p->
next!
if(p->
next->
data<
x)p=p->
elsebreak;
node*u=newnode;
u->
next=u;
5>
将单链表L中奇数项和偶数项结点分解开,并分别连成一个带头结点单链表,然后再将这两个新链表同时输出在屏幕上,并保留原链表显示结果,方便对照求解结果。
链表元素为(1,2,3,4,5,6,7,8,9,10,20,30,40,50,60)
链表元素为(10,20,30,40,50,60,70,80,90,100)
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->
s=LB;
if(p->
data%2==0){
u=p;
p=p->
q->
next=p;
s->
next=u;
s=s->
}
else{
p=p->
q=q->
6>
求两个递增有序链表L1和L2中公共元素,并以一样方法连接成链表L3。
第一组
第一个链表元素为(1,3,6,10,15,16,17,18,19,20)
第二个链表元素为(1,2,3,4,5,6,7,8,9,10,18,20,30)
第二组
第二个链表元素为(2,4,5,7,8,9,12,22)
第三组
第一个链表元素为()
第二个链表元素为(1,2,3,4,5,6,7,8,9,10)
bingji(listA,listB,list&
node*LB;
node*LC;
node*a;
node*b;
LC=C.get_head();
a=LA->
b=LB->
while(a!
=NULL&
b!
=NULL){
if(a->
data<
b->
data)a=a->
elseif(a->
data>
data)b=b->
else{
node*c=newnode;
c->
data=a->
data;
LC->
next=c;
LC=c;
C.count++;
a=a->
b=b->
LC->
next=NULL;
CPP文件附加:
#include<
iostream.h>
#include<
math.h>
enumerror_code{success,arrange_error};
typedefstructnode{
intdata;
node*next;
}node;
classlist{
public:
list();
intlength()const;
~list(){};
node*get_element(intlocate)const;
node*locate(constintx)const;
error_codecharu(constinti);
error_codeinsert(constintlocate,constinti);
error_codedelete_element(constinti);
node*get_head(){returnhead;
voidseparate(list&
B);
intbingji(listA,listB,list&
C);
voidcreate_R();
voidlist:
show();
private:
intcount;
node*head;
node*rear;
};
list:
list(){
head=newnode;
head->
count=0;
}
intlist:
length()const{
node*p=head->
intcount=0;
while(p!
p=p->
returncount;
voidlist:
create_R(){
intx;
cout<
"
请输入链表中数值,按-1后结束创建"
endl;
cin>
>
x;
node*rear=head;
while(x!
=-1){
node*s=newnode;
data=x;
rear->
next=s;
rear=s;
}
node*list:
get_element(intlocate)const{
if(count==0)return0;
else{
if(locate<
=0||locate>
=count)
return0;
else{
node*p=head;
intk=0;
k<
locate){
p=p->
k++;
returnp;
voi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 合肥 工业大学 数据结构 试验 实验 报告