双向循环链表
**存储结构**
typedef struct DuLNode
{
ElemType data;
struct DuLNode *prior;
struct DuLNode *next;
}DuLNode,*DuLinkList;
//双向链表有助于访问前驱结点
**插入**
Status ListInert_DuL(DuLinkList &L,int i ,ElemType &e)
{
DuLNode *p = L;
int j=0;
if(!p||i<1) return ERROR;
while(p&&j<i-1)
{
p = p->next; ++j;
}
s = new DuLNode;
if(!s) exit(OVERFLOW);
s->dats = e;
s->prior = p; s->next = p->next;
p->next->prior = s; p->next = ;
return OK;
}
**删除**
Status ListDelete_DuL(DuLinkList &L,int i,ElemType &e)
{
DuLNode *p = L; int j=0;
if(i<1||!p) return ERROR;
while(p&&j<i-1){
p = p->next; ++j;
}
e = p->data;
p->prior->next = p->next;
p->next->prior = p->prior;
free(p);p=NUll;
return OK;
}
双向循环链表
最新推荐文章于 2021-11-28 10:04:58 发布