Created
March 29, 2021 00:49
-
-
Save loyio/b86110a4af3ef8d0c22afd0fe30cd3c0 to your computer and use it in GitHub Desktop.
SequenceList Insert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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