Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SequenceList Insert
Status ListInsert_Sq(SqList *L, int i, LElemType_Sq e)
{
LElemType_Sq *newbase;
LElemType_Sq *p, *q;
if(i<1 || i>(*L).length+1)
return ERROR;
if((*L).length >= (*L).listsize)
{
newbase = (LElemType_Sq*)realloc((*L).elem, ((*L).listsize+LISTINCREMENT)*sizeof(LElemType_Sq));
if(!newbase)
exit(OVERFLOW);
(*L).elem = newbase;
(*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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment