双向链表的结构定义如下:
typdedef struct DuLNode{
ElemType data;
struct DuLNode *prior,*next;
}DuLNode,*DuLinkList;
```
双向循环链表:
1:双向链表的插入(ab之间)
1:s->prior=p->prior;
2:p->prior->next=s;
3:s->next=p;
4;p->prior=s;
完整的插入算法:
void ListInsert_DuL(DuLinkList &L,int i,ElemType e){
//在带头结点的双向循环链表L中第i个位置之前插入元素e
if(!(p=GetElemP_Dul(i))) return ERROR;
s=new DuLNode;
s-data=e;
s-prior=p->prior;
p->prior->next=s;
s->next=p;
p->prior=s;
return OK;
}//LinkInsert_DuL
2:双向链表的删除:
1:p->prior->next=p->next;
2: p->next->prior=p->prior;
实现代码:
void ListDelete_DuL(DuLink &L,int i,ElemType &e){
//删除带头结点的双向循环链表L的第i个元素,并用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;
}