数据结构作业2012作业1
线性表编程作业:1.将顺序表逆置,要求用最少的附加空间
参考答案#include#include#include#defineLIST_INIT_SIZE100#defineLISTINCREMENT10#defineTRUE1#defineFALSE0#defineOK1#defineERROR0#defineINFEASIBLE-1#defineOVERFLOW-2typedefintStatus;typedefintElemType;typedefstruct{ElemType*elem;intlength;intlistsize;}SqList;//创建空顺序表StatusInitList_Sq(SqList&L){L
elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));if(
elem)exit(OVERFLOW);L
length=0;数据结构作业2012L
listsize=LIST_INIT_SIZE;returnOK;}//顺序表在第i个元素之前插入eStatussxbcr(SqList&L,inti,ElemTypee){ElemType*p,*q;if((iL
length+1))return(ERROR);else{q=&(L
elem[i-1]);for(p=&(L
elem[L
length-1]);p>=q;--p)*(p+1)=*p;*q=e;++L
length;return(OK);}}//顺序表显示voidxsList(SqListL){inti=L
length,k;for(k=0;k20->30->40);(3)InsertList():在有序单链表中插入元素x;(4)ReverseList():单链表就地逆置;(5)DelList():在有