




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、成绩辽宁工程技术大学上机实验报告实验名称顺序表的基本操作的实现院系软件学院专业软件工程班级软件15-3姓名ZOE学号日期2016.09.27实验目的简述本次实验目的: 1掌握线性表顺序存储结构的特点。2掌握线性表顺序存储结构的基本操作(创建、插入、删除)的实现。3. 通过顺序表有序表的合并的实现,掌握顺序表操作特点。实验准备你为本次实验做了哪些准备:在课后认真复习,基于上课的基础上,对于线性表的存储,插入,删除,合并等有了一定的了解,对于书上给出的程序反复捉摸,达到了较熟练的程度。实验进度本次共有 1 个练习,完成 个。实验总结日本次实验的收获、体会、经验、问题和教训:顺序表初始化、插入、删除
2、算法。实现两个有序表合并算法. #include "malloc.h"#include "stdlib.h"#define OK 1#define OVERFLOW -1#define ERROR 0#define LIST_INIT_SIZE 100#define LISTINCREMENT 10typedef int ElemType;typedef int Status;/*-顺序表的存储结构定义-*/typedef structElemType *elem;int length;int listsize;sqlist;/*-初始化顺序表L-*/S
3、tatus InitList_sq(sqlist *L) L->elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType); if(!L->elem) exit(OVERFLOW); L->length=0; L->listsize=LIST_INIT_SIZE; return OK;/*-顺序表L插入-*/Status ListInsert_Sq(sqlist *L,int i,ElemType e) ElemType *newbase,*p,*q; if(i<1|i>L->length+1) re
4、turn ERROR; if(L->length>=L->listsize) newbase=(ElemType*)realloc(L->elem,(L->listsize+LISTINCREMENT)*sizeof(ElemType); if(!newbase) exit(OVERFLOW); L->elem=newbase; L->listsize=L->listsize+LISTINCREMENT; q=&(L->elemi-1); for(p=&(L->elemL->length-1);p>=q;-
5、p) *(p+1)=*p; *q=e; +L->length; return OK;/*-顺序表L删除-*/Status ListDelete_Sq(sqlist *L,int i,ElemType *e) ElemType *p,*q; if(i<1|i>L->length) return ERROR; p=&(L->elemi-1); *e=*p; q=L->elem+L->length-1;/*printf("%d,%d,%d,%d",p,L->elem,L->length,q);*/ for(+p;p&l
6、t;=q;+p) *(p-1)=*p; -L->length; return OK;/*-合并-*/void Mergelist(sqlist La,sqlist Lb,sqlist Lc)int i,j,k;i=j=k=0;while(i<La.length)&&(j<Lb.length) if(La.elemi<Lb.elemj) Lc.elemk+ = La.elemi+; else Lc.elemk+=Lb.elemj+; while(i<La.length) Lc.elemk+ =La.elemi+; while(j<Lb.leng
7、th) Lc.elemk+ =Lb.elemj+;/*-main函数-*/main() sqlist La,Lb,Lc; int i; int n=5; ElemType e;/*-INIT-*/ if(InitList_sq(&La) printf("Init is ok!n"); printf("Length: %dn",La.length); printf("Listsize: %dnn",La.listsize); else printf("error!"); /*-INIT-*/ if(InitL
8、ist_sq(&Lb) printf("Init is ok!n"); printf("Length: %dn",Lb.length); printf("Listsize: %dnn",Lb.listsize); else printf("error!");/*-INIT-*/ if(InitList_sq(&Lc) printf("Init is ok!n"); printf("Length: %dn",Lc.length); printf("Li
9、stsize: %dnn",Lc.listsize); else printf("error!"); /*-顺序表La输入初始值-*/ printf("Please input the values of La:n"); for(i=1;i<=n;i+) scanf("%d",&e) ; if(ListInsert_Sq(&La,i,e)!=OK) break; for(i=1;i<=La.length;i+) printf("e%d=%dn",i-1,La.elemi-1);
10、 printf("Length: %dnn",La.length);/*-INSERT-*/ printf("Please input the place of insert:n"); scanf("%d",&i); printf("Please input the elemvalue:n"); scanf("%d",&e); if(ListInsert_Sq(&La,i,e)=OK) for(i=1;i<=La.length;i+) printf("e%
11、d=%dn",i-1,La.elemi-1); printf("Length: %dnn",La.length); /*-DELETE-*/ printf("Please input the place of delete:n"); scanf("%d",&i); if(ListDelete_Sq(&La,i,&e)=OK) printf("The deleted elem is: %dn",e); for(i=1;i<=La.length;i+) printf("
12、e%d=%dn",i-1,La.elemi-1); printf("Length: %dn",La.length);/*-顺序表Lb输入初始值-*/ printf("Please input the values of Lb:n"); for(i=1;i<=n;i+) scanf("%d",&e) ; if(ListInsert_Sq(&Lb,i,e)!=OK) break; for(i=1;i<=Lb.length;i+) printf("e%d=%dn",i-1,Lb.elemi-1); printf("Length: %dnn",Lb.length); /*-合并-*/ Lc.length=La.length+Lb.length; Mergelist(La,Lb,Lc); for(i=1;i<=Lc.length;i+) printf("n合并后的数组为n"); printf("e%d=%dn",i-1,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 ISO/IEC 23090-7:2022/AMD1:2024 EN Information technology - Coded representation of immersive media - Part 7: Immersive media metadata - Amendment 1: Common metadata for imme
- 【正版授权】 ISO 7718-2:2025 EN Aircraft - Passenger doors interface requirements for connection of passenger boarding bridge or passenger transfer vehicle - Part 2: Upper deck doors
- 【正版授权】 ISO 16900-11:2025 EN Respiratory protective devices - Methods of test and test equipment - Part 11: Determination of field of vision
- 【正版授权】 IEC 81355-1:2024 EN/FR Industrial systems,installations and equipment and industrial products - Classification and designation of information - Part 1: Basic rules and clas
- 2025年集成电路代工厂商业秘密保护合同
- 2025年动力调谐陀螺平台项目建议书
- 提升学校艺术教育影响力的策略计划
- 医院宣传工作总结与改进方法计划
- 班级传统文化传承活动的计划
- 营养科膳食服务效果评估与改进计划
- 一次性纤维环缝合器
- 中华民族的形成与发展
- 2023年上海中侨职业技术大学单招考试职业技能考试模拟试题及答案解析
- 儿科抗生素使用
- 中国教育公益领域发展报告
- 第2章第1节有机化学反应类型课件高二下学期化学鲁科版选择性必修3
- 绿化工程承包合同 绿化工程承包合同范本(二篇)
- 建筑财务出纳年终总结PPT模板下载
- GB/T 9574-2001橡胶和塑料软管及软管组合件试验压力、爆破压力与设计工作压力的比率
- 三位数乘一位数练习题(300道)
- 校本课程《竹之匠艺》
评论
0/150
提交评论