[理科实验报告精品]线性表基本操作 实验报告.doc

上传人:仙人指路1688 文档编号:4233277 上传时间:2023-04-10 格式:DOC 页数:20 大小:355.50KB
返回 下载 相关 举报
[理科实验报告精品]线性表基本操作 实验报告.doc_第1页
第1页 / 共20页
[理科实验报告精品]线性表基本操作 实验报告.doc_第2页
第2页 / 共20页
[理科实验报告精品]线性表基本操作 实验报告.doc_第3页
第3页 / 共20页
[理科实验报告精品]线性表基本操作 实验报告.doc_第4页
第4页 / 共20页
[理科实验报告精品]线性表基本操作 实验报告.doc_第5页
第5页 / 共20页
点击查看更多>>
资源描述

《[理科实验报告精品]线性表基本操作 实验报告.doc》由会员分享,可在线阅读,更多相关《[理科实验报告精品]线性表基本操作 实验报告.doc(20页珍藏版)》请在三一办公上搜索。

1、院 系: 计算机科学学院 专 业: 计算机科学与技术 年 级: 课程名称: 数据结构 学 号: 姓 名: 指导教师: 2011年 03 月 26 日年级班号学号专业计算机科学与技术姓名实验名称线性表基本操作实验类型设计型综合型创新型YES实验目的或要求目的:实现线性表基本操作要求:1、实现线性表的插入,删除,求表长,查找e元素的前驱、后继,查找第i个位置的元素等基本操作。2、程序以菜单方式工作,其中一个选项控制退出程序,其他选项可循环进行选择。实验记录实验源代码:#include #include #include typedef structint num;char name20;int a

2、ge;student;typedef structstudent *elem;int len;int maxsize;sqlist; void InitList_Sq(sqlist &L)L.elem=(student*)malloc(100*sizeof(student);L.len=0;L.maxsize=100;(写不完时,可另加附页。)实验记录 int ListInsert_Sq(sqlist &L)char con=y;int i=0;while(con=y)|(con=Y)if(L.len100)printf(Number:);scanf(%d,&L.elemi.num);prin

3、tf(Name:);scanf(%s,L.elemi.name);printf(Age:);scanf(%d,&L.elemi.age);i+;L.len+; printf(Do you want to contiune?(Y/N);getchar();scanf(%s,&con); while(con!=y)&(con!=Y)&(con!=N)&(con!=n)printf(you can not choice butyandn,please choice again!);getchar();scanf(%s,&con);elsecon=n;return 1;(写不完时,可另加附页。)实验记

4、录 int output_sq(sqlist &L)int j;for(j=0;ji-2;j-) L.elemj+1=L.elemj; printf(Number:);scanf(%d,&L.elemi-1.num);printf(Name:);scanf(%s,L.elemi-1.name);printf(Age:);scanf(%d,&L.elemi-1.age);L.len+; void listdelete(sqlist &L)int i,j;printf(which place do you want to delete?);scanf(%d,&i);for(j=i;jL.len-1

5、;j+);L.elemj=L.elemj+1;L.len-;(写不完时,可另加附页。)实验记录 void mergelist(sqlist &L,sqlist &R,sqlist &C)int i,j,k;i=j=0;k=0;while(i=L.len-1)&(j=R.len-1)if(L.elemi.num=R.elemj.num) C.elemk.num=L.elemi.num; strcpy(C.elemk.name,L.elemi.name); C.elemk.age=L.elemi.age; +k;+i;C.len+;elseC.elemk.num=R.elemj.num; strc

6、py(C.elemk.name,R.elemj.name); C.elemk.age=R.elemj.age; +k;+j;C.len+;while(i=L.len-1) C.elemk.num=L.elemi.num; strcpy(C.elemk.name,L.elemi.name); C.elemk.age=L.elemi.age; +k;+i;C.len+;while(j=R.len-1) C.elemk.num=R.elemj.num; strcpy(C.elemk.name,R.elemj.name); C.elemk.age=R.elemj.age; +k;+j;C.len+;(

7、写不完时,可另加附页。)实验记录 int main() int choice ; sqlist L,R,C; InitList_Sq(L); InitList_Sq(R); InitList_Sq(C); while(choice!=8) printf(*CONTENT*n);printf(* If you want to write a new list of student s information * choice 1 *n);printf(* If you want to visit zhe student information list * choice 2 *n);printf

8、(* If you want to add more to the student information list * choice 3 *n);printf(* If you want to delete some of the student information list * choice 4 *n);printf(* If you want to visit one of the student in zhe list * choice 5 *n);printf(* If you want to add the two list to a new one * choice 6 *n

9、);printf(* If you want to visit zhe list which include 2 list * choice 7 *n);printf(* If you want to quit this program * choice 8 *n);printf(*n);printf( n);printf(which do you want to choice? just type zhe number for choice); scanf(%d,&choice);(写不完时,可另加附页。)实验记录 switch(choice)case 1: int m; printf(wh

10、ich list do you want to insert?); scanf(%d,&m); if(m=1) ListInsert_Sq(L); else ListInsert_Sq(R); break;case 2: int d; printf(which list do you want to out put?); scanf(%d,&d); if(d=1) output_sq(L); else output_sq(R);break;case 3: int a; printf(which list do you want to add one student?); scanf(%d,&a

11、); if(a=1) insert(L); else insert(R);break;case 4: int b; printf(which list do you want to delete one student?); scanf(%d,&b); if(b=1) listdelete(L); else listdelete(R); break;(写不完时,可另加附页。)实验记录 case 5: int c; printf(which list do you want to getelem?); scanf(%d,&c); if(c=1) getelem(L); else getelem(

12、R);break; case 6: mergelist(L,R,C);printf(ok!n); break; case 7:output_sq(C);printf(ok!n);break;case 8:break;default:printf(n);printf(n);printf (please make zhe right choice!n);printf(n);printf(n);break;return 1; (写不完时,可另加附页。)实验记录 运行结果如下:显示菜单界面,用户根据自己的需求选择需要处理的选项。(写不完时,可另加附页。)实验记录 用户选择需要插入的线性表:输入元素信息

13、:是否继续插入:待添加的隐藏文字内容2(写不完时,可另加附页。)实验记录继续插入信息:(写不完时,可另加附页。)实验记录 用户往线性表1中添加元素:访问线性表1中元素并输出:(写不完时,可另加附页。)实验记录 访问线性表1中某元素:再创建一个线性表2:(写不完时,可另加附页。)实验记录将线性表1,2合并为一个新的线性表:删除线性表2中某一元素:(写不完时,可另加附页。)实验记录 访问合并的新线性表:(写不完时,可另加附页。)实验记录 退出:(写不完时,可另加附页。)组内分工(可选)实验结果分析及心得体会1. 用户根据自己的需求创建线性表,向其中添加元素(元素信息:学号,姓名,年龄);2. 用户可以访问线性表并输出其内容;3. 用户可向线性表中添加元素;4. 用户可以删除线性表中的元素;5. 用户可以访问查找线性表中的某个元素;6. 用户可以将创建的两个线性表合并成一个线性表并将其内容输出;用户自定义函数:插入函数 输出函数 取元素函数 删除函数 线性表合并函数 心得体会:通过这次试验,我掌握了线性表的创建,元素的插入,删除,访问,线性表的合并等操作,体会到指针的优越性,运用switch-case语句实现菜单的功能。 成绩评定教师签名: 年 月 日备注:源代码附后,源代码要求有注释说明

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

当前位置:首页 > 办公文档 > 其他范文


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号