this file is some large,but i hope you can read it , and tell me ,wicth can be changed. thanks in advance.
Code:
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 1
#define OK 1
#define ERROR 0
typedef int ElemType
typedef int Status
typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList &L){
L.elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(! L.elem) return ERROR;
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
int ListInsert_Sq(SqList &L,int i,ElemType e){
if(i<1||i>L.length+1) return ERROR;
if(L.length>=L.listsize)
newbase=(ElemType *)realloc((L.listsize+LISTINCREMENT)*sizeof(ElemType));
if(! l.elem) return ERROR;
L.elem=base;
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++;
return OK;
}
int ListDelete_Sq(SqList &L,int i,Elemtype e){
if(i<1||i>L.length+1) return ERROR;
q=&L.elem[i-1];
e=*q;
for(q;q<=(p=&L.elem[L.length-1]);++q) *q=*(q+1);
--L.length;
return OK;
}
int LocateElem_sq(sqList L,Elemtype Status (* compare)(ElemType,ElemType)){
while(i<L.length&&!(* compare)(*p++,e)) ++i;
if(i<=L.length) return i;
else return ERROR;
}
void MergeList_Sq(SqList La,SqList Lb,SqList &Lc){
pa=La.elem; pb=Lb.elem;
pa_last=La.elem+La.length-1;
pb_last=Lb.elem+Lb.length-1;
Lc.elem=(ElemType *)malloc((La.listsize+Lb.listsize)*(sizeof(ElemType)));
pc=Lc.elem
if(! Lc.elem) return ERROR;
Lc.listsize=La.listsize+Lb.listsize;
while(pa<=pa_last&&pb<=pb_last)){
if(*pa<*pb) *pc=*pa; ++pa;
else *pc=*pb; ++pb;
}
while(pa<pa_last) *pc=*pa;
while(pb<pb-last) *pc=*pb;
return OK;
}
void List_OutPut(SqList &L){
for(i=0,i<L.length;i++) printf("ElemType",l.elem[i]);
}
main()
{
SqList *L;
char cmd;
int i,t;
clscr();
printf("I......Insert\n");
printf("D......Delete\n");
printf("Q......Quit\n");
do{
do{
cmd=getchar();
}while(cmd!="d"||cmd!="q"||cmd!="i");
switch(cmd){
case "i":scanf(&e);
scanf(&i);
ListInsert_Sq(L,i,e);
List_OutPut(L);
break;
case "d":scanf(&e);
scanf(&i);
ListDelete_Sq(L,i,e);
List_OutPut(L);
break;
}while(cmd!="q");
}