双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx

上传人:b****1 文档编号:4279343 上传时间:2023-05-03 格式:DOCX 页数:10 大小:61.97KB
下载 相关 举报
双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx_第1页
第1页 / 共10页
双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx_第2页
第2页 / 共10页
双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx_第3页
第3页 / 共10页
双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx_第4页
第4页 / 共10页
双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx_第5页
第5页 / 共10页
双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx_第6页
第6页 / 共10页
双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx_第7页
第7页 / 共10页
双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx_第8页
第8页 / 共10页
双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx_第9页
第9页 / 共10页
双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx_第10页
第10页 / 共10页
亲,该文档总共10页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx

《双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx(10页珍藏版)》请在冰点文库上搜索。

双向链表的构建插入删除和显示实验报告材料Word格式文档下载.docx

1.首先建立一个带头结点的非空的双向链表。

建立函数creat,操作与建立线性链表类似,但需要修改两个方向的指针。

本实验以输入6个学生的数据为例。

2.建立函数GetElemP_DuL,得到第i个元素的位置指针。

3.对链表进行插入操作。

建立函数ListInsert_DuL,输入要插入的学生数据以及位置,调用函数GetElemP_DuL,插入成功返回1,否则返回0。

4.对链表进行删除操作。

建立函数ListDelete_DuL,输入要删除的学生位置,调用函数GetElemP_DuL,删除成功返回1,否则返回0。

5.对链表的结果进行输出与显示。

建立函数print,对链表进行正向和反向的输出。

6.建立main函数,把以上五个函数整合到一个程序之中,当输入的数据不为0时可进行多次删除,插入操作,并对每一次的结果进行显示。

四.实验方法

运行环境:

VisualC++6.0

把所有程序思想写成代码,通过VisualC++编译,得到结果,即运行成功。

本实验程序代码:

#include"

stdio.h"

malloc.h"

#defineNULL0

#defineLENsizeof(structstudent)

#defineOK1

#defineERROR0

structstudent

{

intdata;

structstudent*prior;

structstudent*next;

};

intn;

structstudent*creat(void)

structstudent*L;

structstudent*p1,*p2;

L=(structstudent*)malloc(LEN);

L->

next=NULL;

prior=NULL;

n=0;

p1=p2=(structstudent*)malloc(LEN);

scanf("

%d"

&

p1->

data);

while(p1->

data!

=0)

{

n=n+1;

if(n==1)

{L->

next=p1;

prior=L;

}

else

{

p2->

next->

prior=p2;

}

p2=p1;

p1=(structstudent*)malloc(LEN);

scanf("

}

p2->

next=L;

return(L->

next);

voidprint(structstudent*head)

structstudent*p;

p=head;

printf("

正向输出:

\n"

);

if(head!

=NULL)

do{

printf("

%d\n"

p->

p=p->

next;

}while(p!

=head->

prior);

反向输出:

if(p==head->

prior)

{p=p->

prior;

structstudent*GetElemP_DuL(structstudent*L,inti)

intj=1;

p=L;

while(j!

=i)

p=p->

j++;

returnp;

intListInsert_DuL(structstudent*L,inti,inte)

structstudent*p,*s;

if(!

(p=GetElemP_DuL(L,i)))

returnERROR;

(s=(structstudent*)malloc(LEN)))

s->

data=e;

prior=p->

p->

prior->

next=s;

next=p;

prior=s;

n=n+1;

returnOK;

intListDelete_DuL(structstudent*L,inti)

inte;

e=p->

data;

next=p->

free(p);

n=n-1;

voidmain()

structstudent*head;

inti,e;

请输入学生的数据:

head=creat();

print(head);

请输入要插入的位置以及数据:

%d%d"

i,&

e);

while(e!

if(ListInsert_DuL(head,i,e)==1)

print(head);

printf("

请输入要删除的位置:

i);

while(i!

if(ListDelete_DuL(head,i)==1)

五.实验结果

运行结果截图:

表明双向链表构建成功。

六.实验结论

可以通过指针的方法建立双向链表并对其进行插入,删除和显示操作。

 

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 初中教育 > 语文

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2