- 18
- 0
- 约4.16千字
- 约 13页
- 2018-02-25 发布于浙江
- 举报
南邮通达数据结构b存储结构的比较实验报告
实 验 报 告
课程名称 数 据 结 构B 实验名称 存储结构的比较 实验时间 2015 年 月 日 指导单位 计算机学院计算机科学与技术系 指导教师 徐鹤
学生姓名 陈世骏 班级学号 学院(系) 通达学院 专 业 信息工程
实 验 报 告
实验名称 存储结构的比较 指导教师 徐鹤 实验类型 设计 实验学时 2 实验时间 2015.11.12 一、实验目的和要求
理解线性表数据结构,掌握线性表的顺序和链接这两种存储表示方法。
分别用顺序存储和链接存储实现线性表的基本操作。
比较两者的优缺点,并说明两者的应用场合。 二、实验内容:
(一)分别用顺序存储和链接存储实现线性表的基本操作(基本操作见P58线性表ADT)。参考教材4.1.2线性表的顺序表示和4.1.3线性表的链接表示。
(二)顺序表操作:具体要求见课本P295实习5的实习内容和要求(1)。 三、实验环境(实验设备)
Visual C++ 6.0
(一)顺序存储实现线性表的基本操作
#include stdio.h
#include stdlib.h
#define MAX 20
typedef struct
{
int element[MAX];
int size;
}List;
void Createlist(List *lst,int n) //创建一个顺序表
{ int i;
printf(\nInput the values of the list:\n);
for(i=0;in;i++)
{
scanf(%d,lst-element[i]);
lst-size++;
}
}
void Insert(List *lst,int pos,int x) //在顺序表中第pos的位置上插入x
{
int i;
if(lst-size=MAX) //上溢出判断
printf(\nOverflow!\n);
if(pos0||poslst-size) //合法性验证
printf(\nOut of bounds!\n);
for(i=lst-size-1;i=pos;i--) //插入从后面开始,移动数据元素
lst-element[i+1]=lst-element[i];
lst-element[pos]=x;
lst-size++; //长度变化
}
void Remove(List *lst,int pos) //删除顺序表中第pos个数据元素
{
int i;
if(lst-size=0) //下溢出判断
printf(\nUnderflow\n);
if(pos0||pos=lst-size) //合法性验证
printf(\nOut of bounds!\n);
for(i=pos;ilst-size;i++) //删除从前面开始,移动数据元素
lst-element[i]=lst-element[i+1];
lst-size--; //长度变化
}
void Output(List *lst) //输出顺序表中的数据元素
{
int i;
printf(\nThe result is:\n);
for(i=0;ilst-size;i++)
printf(%d ,lst-element[i]);
}
void main()
{
int n,pos1,x,pos2;
List *lst;
lst=(List *)malloc(sizeof(List)); //定义空顺序表
lst-size=0;
printf(\nInput the size of the list:\n);
scanf(%d,n);
Createlist(lst,n);
Output(lst);
printf(\nInput pos x:\n);
scanf(%d%d,pos1,x);
Insert(lst,pos1,x);
Output(lst);
printf(\nInput pos:);
scanf(%d,pos2);
Remove(lst,pos2);
Output(lst);
}
(二)链接存储实现线性表的基本操作
#includestdio.h
#includemalloc.h
#includestdlib.h
#includectype.h
typedef int T;
T* InputElement()
{
您可能关注的文档
最近下载
- 中学生交通安全教育培训课件PPT.pptx VIP
- 牵引供电系统 牵引变电所供电方式 牵引变电所供电方式.ppt VIP
- 1.03 玉米高产管理技术 - (先锋克劳森).pptx VIP
- 杜邦公司讲座杜邦安全管理介绍.pptx VIP
- 2025年广西财经学院辅导员招聘考试笔试模拟试题及答案解析.docx VIP
- (正式版)DB65∕T 3611-2023 《农业用水定额》.pdf VIP
- 2025年江苏省南京市中考英语试卷(含解析).pdf VIP
- (2025年版)国家基层高血压防治管理指南PPT课件.pptx VIP
- 2024年山东交通职业学院高职单招(英语/数学/语文)笔试题库含答案解析.docx VIP
- 2017年-2022年暨南大学考研701美学原理真题.pdf
原创力文档

文档评论(0)