Skip to content

Instantly share code, notes, and snippets.

@loyio
Created March 29, 2021 00:49
Show Gist options
  • Select an option

  • Save loyio/b86110a4af3ef8d0c22afd0fe30cd3c0 to your computer and use it in GitHub Desktop.

Select an option

Save loyio/b86110a4af3ef8d0c22afd0fe30cd3c0 to your computer and use it in GitHub Desktop.

Revisions

  1. loyio created this gist Mar 29, 2021.
    28 changes: 28 additions & 0 deletions SequenceListInsert.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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;
    }