Status ListInsert(SqList* L, int i, ElemType e) {
ElemType* newbase;
if(L == NULL && (*L).elem == NULL && (*L).length == 0 )
{
return ERROR;
}
if(i>(*L).length && i<0)
{
return ERROR;
}
if((*L).length >= (*L).listsize) {
newbase = (ElemType*) realloc((*L).elem, ((*L).listsize + LISTINCREMENT) * sizeof(ElemType));
if(newbase == NULL) {
exit(OVERFLOW);
}
(*L).elem = newbase;
(*L).listsize += LISTINCREMENT;
}
for(int j = (*L).length;j>i;j--)
{
(*L).elem[j] = (*L).elem[j-1];
}
(*L).elem[i-1] = e;
(*L).length++;
return OK;
}
Status ListDelete(SqList* L, int i, ElemType* e) {
if(L == NULL && (*L).elem == NULL && (*L).length == 0 )
{
return ERROR;
}
if(i>(*L).length && i<0)
{
return ERROR;
}
int a = i-1;
*e = (*L).elem[a];
for(int j = i;j<(*L).length;j++)
{
(*L).elem[j-1] = (*L).elem[j];
}
(*L).length--;
return OK;
}
|