华农数据结构上机实验答案.doc

华农数据结构上机实验答案.doc

ID:59342631

大小:229.00 KB

页数:90页

时间:2020-10-31

华农数据结构上机实验答案.doc_第1页
华农数据结构上机实验答案.doc_第2页
华农数据结构上机实验答案.doc_第3页
华农数据结构上机实验答案.doc_第4页
华农数据结构上机实验答案.doc_第5页
资源描述:

《华农数据结构上机实验答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、数据结构上机答案1.1顺序线性表的基本操作#include#include#defineOK1#defineERROR0#defineLIST_INIT_SIZE100#defineLISTINCREMENT10#defineElemTypeinttypedefstruct{int*elem,length,listsize;}SqList;intInitList_Sq(SqList&L){L.elem=(ElemType*)malloc(LIST_INIT_

2、SIZE*sizeof(ElemType));L.length=0;L.listsize=LIST_INIT_SIZE;returnOK;}intLoad_Sq(SqList&L){inti;if(L.length==0)printf("TheListisempty!");else{printf("TheListis:");for(i=0;i

3、SqList&L,inti,inte){if(i<1

4、

5、i>L.length+1)returnERROR;ElemType*newbase,*q,*p;if(L.length>=L.listsize){newbase=(ElemType*)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(ElemType));L.elem=newbase;L.listsize+=LISTINCREMENT;}q=&(L.elem[i-1]);for(p=&(L.e

6、lem[L.length-1]);p>=q;--p)*(p+1)=*p;*q=e;++L.length;returnOK;}intListDelete_Sq(SqList&L,inti,int&e){ElemType*q,*p;if(i<1

7、

8、i>L.length)returnERROR;p=&(L.elem[i-1]);e=*p;q=L.elem+L.length-1;for(++p;p<=q;p++)*(p-1)=*p;L.length--;returnOK;}intmain(){SqLis

9、tT;inta,i;ElemTypee,x;if(InitList_Sq(T)){printf("ASequenceListHasCreated.");}while(1){printf("1:Insertelement2:Deleteelement3:Loadallelements0:ExitPleasechoose:");scanf("%d",&a);switch(a){case1:scanf("%d%d",&i,&x);if(!ListInsert_Sq(T,i,x)

10、)printf("InsertError!");elseprintf("TheElement%disSuccessfullyInserted!",x);break;case2:scanf("%d",&i);if(!ListDelete_Sq(T,i,e))printf("DeleteError!");elseprintf("TheElement%disSuccessfullyDeleted!",e);break;case3:Load_Sq(T);break;case0:retur

11、n1;}}}1.2合并顺序表#include#include#defineOK1#defineERROR0#defineLIST_INIT_SIZE100#defineLISTINCREMENT10#defineElemTypeinttypedefstruct{int*elem,length,listsize;}SqList;intInitList_Sq(SqList&L){L.elem=(ElemType*)malloc(LIST_INIT_SIZE*si

12、zeof(ElemType));L.length=0;L.listsize=LIST_INIT_SIZE;returnOK;}intLoad_Sq(SqList&L){inti;for(i=0;i

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。