双向链表的插入

Snipaste_2023-08-08_10-47-31

void ListInsert_DuL(DuLinkList &L,Int i,ElemType e){

//在带头结点的双向循环链表L中第ⅰ个位置之前插入元素e

if(!(p=GetElemP_DuL(L,i)))return ERROR;

s=new DuLNode; s->date = e;

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

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

return OK;

}//Listlnsert_DuL

双向链表的删除

Snipaste_2023-08-08_11-28-26

void ListDelete_DuL(DuLink &L,Int i,ElemType &e){

//删除带头结点的双向循环链表L的第ⅰ个元素,并用e返回。

if(!(p=GetElemP_DuL(L,i))) return ERROR;

e = p->data;

p->prior->next = p->next;

p->next ->prior = p->prior;

free(p);

return OK;

}//ListDelete_DuL