一个线性表的程序问题
是做一个线性表的建立、插入、删除#define LIST-INIT-SIZM 100
#define LISTINCREMENT 10
typedef struct {
int *elem;
int length;
int listsize;
}sqlist
void InitList-sq(sqlist &L)
viod ListIntsert-sq(sqlist &L,int i,int e)
viod Listdelete-sq
main()
{ int *p,*q,i,e;
sqlist L;
Initlist-sq(&L);
printf("Please put into two number to i and e:");
scanf("%d,%d",&i,&e);
ListInsert-sq(&L,i,e);
scanf("%d,%d",&i,&e);
Listdelete-sq(&L,i,e);
}
void InitList-sq(sqlist &L)
{
l.elem=(int *)malloc(LIST-INIT-SIZE*sizeof(int));
if(!L.elem)exit(OVERFLOW);
L.length=0;
L.listsize=LIST-INIT-SIZE;
return OK;
}
viod ListIntsert-sq(sqlist &L,int i,int e)
{
int *newbase;
if(i<1||i>L.length+1) return ERROR;
if(L.length>=L.listsize)
{
newbase=(int *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(int));
if(!newbase)exit(OVERFLOW);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
Q=&(L.elem[L.length-1];p>=q;--p)
*(p+1)=*p;
*q=e;
++L.lentgh;
return OK;
}
viod Listdelete-sq(sqlist &L,int i,int &e)
{
if((i<1)||(i>L.length))return ERROR;
p=&(L.elem[i-1];
e=*p;
q=L.elem+L.length-1;
for(++p;p<=q;++p)*(p-1)=*p;
--L.length;
return OK;
}
有颜色的地方提示有错误! ]