数据结构 单链表操作验证Word格式文档下载.docx
- 文档编号:4570025
- 上传时间:2023-05-03
- 格式:DOCX
- 页数:11
- 大小:113.10KB
数据结构 单链表操作验证Word格式文档下载.docx
《数据结构 单链表操作验证Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《数据结构 单链表操作验证Word格式文档下载.docx(11页珍藏版)》请在冰点文库上搜索。
D.删除操作中依次输入1,删除位于1的元素
2.概要设计
1)基本操作:
structstu*creat()
操作结果:
构造一单链表
Structstu*ins(structstu*head)
初始条件:
单链表已存在
插入元素
Structstu*del(structstu*head)
删除元素
Voidfind(structstu*head)
单链表L已存在
查找元素
Voidoutput(structstu*head)
初始条件:
输出元素
Voidmain()
主函数
2)本程序包含6个函数:
①主函数main()
②显示单链表内容函数output()
③建立元素函数creat()
④插入元素函数ins()
⑤删除元素函数del()
⑥查找元素函数find()
主函数控制五个函数:
3.详细设计
实现概要设计中定义的所有的数据类型,对每个操作给出伪码算法。
对主程序和其他模块也都需要写出伪码算法。
1)结点类型和指针类型
structstu
{
intnum;
charname[20]
floatChinese,maths,English;
structstu*next;
};
2)单链表的基本操作
Voidoutput(structstu*head)
(伪码算法)
Structstu*creat()
Structstu*ins(structstu*head)
Structstu*del(structstu*head)
Voidfind(structstu*head)
Voidmain()
4.程序源码
#include<
stdio.h>
#include<
stdlib.h>
malloc.h>
#defineNULL0
#defineLENsizeof(structstu)
structstu
intnum;
charname[20];
structstu*next;
};
intn;
voidoutput(structstu*head)
structstu*p;
p=head;
printf("
学号\t姓名\t语文\t数学\t英语\t\n"
);
for(p=head;
p!
=NULL;
p=p->
next)
{
%d\t%s\t%.1f\t%.1f\t%.1f\n"
p->
num,p->
name,p->
Chinese,p->
maths,p->
English);
}
}
structstu*creat()
{
structstu*head;
structstu*p1,*p2;
n=0;
学号,姓名,语文,数学,英语:
\n"
输入00000停止!
p1=p2=(structstu*)malloc(LEN);
scanf("
%d%s%f%f%f"
&
p1->
num,p1->
name,&
Chinese,&
maths,&
head=NULL;
while(p1->
num!
=0)
n=n+1;
if(n==1)head=p1;
elsep2->
next=p1;
p2=p1;
p1=(structstu*)malloc(LEN);
p2->
next=NULL;
return(head);
structstu*ins(structstu*head)
structstu*p0,*p1,*p2;
请输入插入的学生信息:
p1=head;
p0=creat();
if(head==NULL)
head=p0;
p0->
else{
while((p0->
num>
num)&
&
(p1->
next!
=NULL))
{
p2=p1;
p1=p1->
next;
}
if(p0->
num<
num)
if(head==p1)head=p0;
elsep2->
next=p0;
p0->
else
p1->
n=n+1;
structstu*del(structstu*head)
printf("
\n链表为空!
else
p1=head;
请输入所需删除号码:
%d"
num);
while(num!
=p1->
num&
=NULL)
p1=p1->
if(num==p1->
if(p1==head)head=p1->
p2->
next=p1->
删除:
%d\n"
num);
n=n-1;
printf("
对不起,%d不在链表中!
\n"
return(head);
voidfind(structstu*head)
structstu*p1;
请输入所需查找号码:
p1=p1->
if(num==p1->
学号:
%d姓名:
%s语文:
%.1f数学:
%.1f英语:
%.1f\n"
p1->
name,p1->
Chinese,p1->
maths,p1->
voidmain()
intselect;
while
(1)
1.建立2.插入3.删除4.查找5.输出6.退出\n"
请输入操作序号:
select);
switch(select)
case1:
head=creat();
break;
case2:
head=ins(head);
case3:
head=del(head);
case4:
find(head);
case5:
output(head);
case6:
exit(0);
}
5.调试分析
在往电脑中输入程序时,由于马虎,有的落了标点符号,有的落了或写错了字母,有的语句也出现了错误,终于将它们一一修正过来。
6.使用说明
程序名为LinkList.exe,运行环境为VisualC++。
程序执行后显示
1.建立2.插入3.删除4.查找5.输出6.退出
然后输入数字选择执行不同的功能。
要求首先输入足够多的插入元素,才可以进行其他的操作。
每执行一次功能,就会显示执行的结果(正确或错误)以及执行后单链表的内容。
选择1:
显示“学号,姓名,语文,数学,英语:
”
要求输入足够多的元素。
选择2:
显示“请输入插入的学生信息:
”
要求输入要插入的位置和元素的值(都是整数)。
选择3:
显示“请输入所需删除号码:
要求输入要删除元素的位置,执行成功后返回元素的值。
选择4:
显示“请输入所需查找号码:
要求输入要查找元素的值,执行成功后返回元素在表中的位置。
选择5:
显示“学号姓名语文数学英语”
要求输出所有元素的值。
选择6:
显示“Pressanykeytocontinue”
要求按任意键继续操作或退出。
7.测试结果
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 单链表操作验证 单链表 操作 验证
![提示](https://static.bingdoc.com/images/bang_tan.gif)