链表

Status ListInsert(LinkList &L,int i,ElemType e)

p=L;j=0;

while(p&&j<i-1)

p=p->next;

++j;

if(!p||j>i-1)

return ERROR;

s=(LinkList)malloc(sizeof(LNode));

s->data=e;

s>next=p->next; p->next=s;

return OK;

 

 

 

void ListInsert(List &L,unsigned i,ElemType e)

{

if(L->length==LIST_INIT_SIZE)

exit(OVERFLOW);

if(i<1||i>L->length+1)

exit(ERROR);

for(unsigned j=L.length-1;j>=i-1;j--)

L.elem[j+1]=L.elem[j];

L.elem[i-1]=e;

L.length++;

posted on 2021-11-13 10:05  STERNSTUN  阅读(31)  评论(0编辑  收藏  举报

导航