Status ListInsert_Sq(SqList &L, int pos, ElemType e)
{
if (L.length == L.listsize)
{
ElemType *tmp = (ElemType *)realloc(L.elem, (L.listsize + LISTINCREMENT) * sizeof(ElemType));
if (!tmp)
exit(OVERFLOW);
L.elem = tmp;
}
if (pos > L.length + 1 || pos < 1)
{
return ERROR;
}
for (int i = L.length; i > pos - 1; i--)
{
L.elem[i] = L.elem[i - 1];
}
L.elem[pos - 1] = e;
L.length++;
return OK;
}
void ListPrint_Sq(SqList L)
{
for (int i = 0; i < L.length - 1; i++)
{
printf("%d ", L.elem[i]);
}
printf("%d\n", L.elem[L.length - 1]);
}
Status ListDelete_Sq(SqList &L, int pos, ElemType &e)
{
e = L.elem[pos - 1];
for (int i = pos - 1; i < L.length; i++)
{
L.elem[i] = L.elem[i + 1];
}
L.length--;
return OK;
}
int ListLocate_Sq(SqList L, ElemType e)
{
for (int i = 0; i < L.length; i++)
{
if (L.elem[i] == e)
{
return i + 1;
}
}
return 0;
}