欢迎来到天天文库
浏览记录
ID:14156137
大小:307.50 KB
页数:184页
时间:2018-07-26
《数据结构实验上机题答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
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_SIZE*sizeof(ElemType));L.length=0
2、;L.listsize=LIST_INIT_SIZE;returnOK;184}intLoad_Sq(SqList&L){inti;if(L.length==0)printf("TheListisempty!");else{printf("TheListis:");for(i=0;i3、4、i>L.length+1)retu5、rnERROR;ElemType*newbase,*q,*p;184if(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.elem[L.length-1]);p>=q;--p)*(p+1)=*p;*q=e;++L.length;retur6、nOK;}intListDelete_Sq(SqList&L,inti,int&e){ElemType*q,*p;if(i<17、8、i>L.length)returnERROR;p=&(L.elem[i-1]);184e=*p;q=L.elem+L.length-1;for(++p;p<=q;p++)*(p-1)=*p;L.length--;returnOK;}intmain(){SqListT;inta,i;ElemTypee,x;if(InitList_Sq(T)){printf("ASequenceListHasCrea9、ted.");}while(1){printf("1:Insertelement2:Deleteelement3:Loadallelements0:ExitPleasechoose:");scanf("%d",&a);184switch(a){case1:scanf("%d%d",&i,&x);if(!ListInsert_Sq(T,i,x))printf("InsertError!");elseprintf("TheElement%disSuccessfullyInserted!",x);b10、reak;case2:scanf("%d",&i);if(!ListDelete_Sq(T,i,e))printf("DeleteError!");elseprintf("TheElement%disSuccessfullyDeleted!",e);break;case3:Load_Sq(T);break;case0:return1;}}}184222222222222222222222222222222222222222222222222222222222222222222222222222222#include<11、stdio.h>#include#defineOK1#defineERROR0#defineLIST_INIT_SIZE100#defineLISTINCREMENT10#defineElemTypeinttypedefstruct{int*elem,length,listsize;}SqList;intInitList_Sq(SqList&L){L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));L.length=0;L.listsize=12、LIST_INIT_SIZE;returnOK;}184intLoad_Sq(SqList&L){inti;for(i=0;i
3、
4、i>L.length+1)retu
5、rnERROR;ElemType*newbase,*q,*p;184if(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.elem[L.length-1]);p>=q;--p)*(p+1)=*p;*q=e;++L.length;retur
6、nOK;}intListDelete_Sq(SqList&L,inti,int&e){ElemType*q,*p;if(i<1
7、
8、i>L.length)returnERROR;p=&(L.elem[i-1]);184e=*p;q=L.elem+L.length-1;for(++p;p<=q;p++)*(p-1)=*p;L.length--;returnOK;}intmain(){SqListT;inta,i;ElemTypee,x;if(InitList_Sq(T)){printf("ASequenceListHasCrea
9、ted.");}while(1){printf("1:Insertelement2:Deleteelement3:Loadallelements0:ExitPleasechoose:");scanf("%d",&a);184switch(a){case1:scanf("%d%d",&i,&x);if(!ListInsert_Sq(T,i,x))printf("InsertError!");elseprintf("TheElement%disSuccessfullyInserted!",x);b
10、reak;case2:scanf("%d",&i);if(!ListDelete_Sq(T,i,e))printf("DeleteError!");elseprintf("TheElement%disSuccessfullyDeleted!",e);break;case3:Load_Sq(T);break;case0:return1;}}}184222222222222222222222222222222222222222222222222222222222222222222222222222222#include<
11、stdio.h>#include#defineOK1#defineERROR0#defineLIST_INIT_SIZE100#defineLISTINCREMENT10#defineElemTypeinttypedefstruct{int*elem,length,listsize;}SqList;intInitList_Sq(SqList&L){L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));L.length=0;L.listsize=
12、LIST_INIT_SIZE;returnOK;}184intLoad_Sq(SqList&L){inti;for(i=0;i
此文档下载收益归作者所有