双向链表的存储结构
//Double Linked List
typedef struct DuLNode
{
ElemType data;
struct DuLNode *prior;
struct DuLNode *next;
}DuLNode, *DuLinkList;
插入
Status ListInsert_DuL(DuLNode *L, int i, ElemType e)
{
//在带头结点的双向链表L中第i个位置之前插入元素e
if(!(p=GetElem_DuL(L,i))
return ERROR;
s = new DuLNode;
s->data = e;
//要用到p->prior的操作先执行
s->prior = p->prior;
p->prior->next = s;
s->next = p;
p->prior = s;
return OK;
}
删除
Status ListDelete_DuL(DuLinkList *L, int i)
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
p->prior->next = p->next;
p->next->prior = p->prior;
delete p;
return OK;
}