Skip to content

Instantly share code, notes, and snippets.

@loyio
Created March 29, 2021 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loyio/b86110a4af3ef8d0c22afd0fe30cd3c0 to your computer and use it in GitHub Desktop.
Save loyio/b86110a4af3ef8d0c22afd0fe30cd3c0 to your computer and use it in GitHub Desktop.
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