南邮通达数据结构b存储结构的比较实验报告.docVIP

  • 18
  • 0
  • 约4.16千字
  • 约 13页
  • 2018-02-25 发布于浙江
  • 举报

南邮通达数据结构b存储结构的比较实验报告.doc

南邮通达数据结构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() {

文档评论(0)

1亿VIP精品文档

相关文档