双向链表插入删除基本操作演示

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
if(!(s=(DuLinkList)malloc(sizeof(DuLNode))))
return ERROR;
s->data=e;
① s->prior=p->prior;
② p->prior->next=s;
③ s->next=p; ④ p->prior=s;
s->data=e;
① s->prior=p->prior;
② p->prior->next=s;
③ s->next=p;
④ p->prior=s;
return OK;
a
b
}
在双向链表中插入结点
Status ListInsert_Dul(DuLinklist &L,int i,ElemType e)
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
if(!(s=(DuLinkList)malloc(sizeof(DuLNode))))
return ERROR;
s->data=e;
① s->prior=p->prior;
② p->prior->next=s;
③ s->next=p; ④ p->prior=s;
在双向链表中插入结点
Status ListInsert_Dul(DuLinklist &L,int i,ElemType e)
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
if(!(s=(DuLinkList)malloc(sizeof(DuLNode))))
return ERROR;
p
return OK;
a
b
}
在双向链表中插入结点
Status ListInsert_Dul(DuLinklist &L,int i,ElemType e)
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
if(!(s=(DuLinkList)malloc(sizeof(DuLNode))))
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
if(!(s=(DuLinkList)malloc(sizeof(DuLNode))))
return ERROR;
s->data=e;
① s->prior=p->prior;
② p->prior->next=s;
③ s->next=p; ④ p->prior=s;
if(!(p=GetElem_DuL(L,i))) return ERROR;
e=p->data; ① p->prior->next=p->next ; ② p->next->prior=p->prior; ③ free(p);
return OK; }
a
b
c
在双向链表中删除结点
Status ListDelete_Dul(DuLinklist &L,int i,ElemType &e) {
return ERROR;
s->data=e;
① s->prior=p->prior;
② p->prior->next=s;
③ s->next=p; ④ p->prior=s;
p
return OK;
a
b
}
① ②④ ③
s
e
在双向链表中删除结点
Status ListDelete_Dul(DuLinklist &L,int i,ElemType &e) {
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
e=p->data;
① p->prior->next=p->next ;
② p->next->prior=p->prior;
③ free(p);
return OK;

}
a
c

在双向链表中删除结点
Status ListDelete_Dul(DuLinklist &L,int i,ElemType &e)
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
e=p->data;
① p->prior->next=p->next ;
② p->next->prior=p->prior;
③ free(p);
return OK;

}
p
a
b
c

在双向链表中删除结点
Status ListDelete_Dul(DuLinklist &L,int i,ElemType &e)
if(!(p=GetElem_DuL(L,i)))
return ERROR; e=p->data; ① p->prior->next=p->next ; ② p->next->prior=p->prior; ③ free(p); return OK; }
p
a
b
c
在双向链表中删除结点
Status ListDelete_Dul(DuLinklist &L,int i,ElemType &e)
return ERROR;
s->data=e;
① s->prior=p->prior;
② p->prior->next=s;
③ s->next=p; ④ p->prior=s;
p
return OK;
a
b
}

s
e
在双向链表中插入结点
Status ListInsert_Dul(DuLinklist &L,int i,ElemType e)
p
return OK;
a
b
}
① ②④ ③
s
e
在双向链表中插入结点
Status ListInsert_Dul(DuLinklist &L,int i,ElemType e)
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
if(!(s=(DuLinkList)malloc(sizeof(DuLNode))))
p
return OK;
a
b
}
①②
s
e
在双向链表中插入结点
Status ListInsert_Dul(DuLinklist &L,int i,ElemType e)
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
if(!(s=(DuLinห้องสมุดไป่ตู้List)malloc(sizeof(DuLNode))))
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
e=p->data;
① p->prior->next=p->next ;
② p->next->prior=p->prior;
③ free(p);
return OK;
}

a
c

{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
if(!(s=(DuLinkList)malloc(sizeof(DuLNode))))
return ERROR;
s->data=e;
① s->prior=p->prior;
② p->prior->next=s;
③ s->next=p; ④ p->prior=s;
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
e=p->data;
① p->prior->next=p->next ;
② p->next->prior=p->prior;
③ free(p);
return OK;

}
p
a
b
c
在双向链表中删除结点
Status ListDelete_Dul(DuLinklist &L,int i,ElemType &e)
return ERROR;
s->data=e;
① s->prior=p->prior;
② p->prior->next=s;
③ s->next=p; ④ p->prior=s;
p
return OK;
a
b
}
s
在双向链表中插入结点
Status ListInsert_Dul(DuLinklist &L,int i,ElemType e)
return ERROR;
s->data=e;
① s->prior=p->prior;
② p->prior->next=s;
③ s->next=p; ④ p->prior=s;
p
return OK;
a
b
}
①②

s
e
在双向链表中插入结点
Status ListInsert_Dul(DuLinklist &L,int i,ElemType e)
p
return OK;
a
b
}
s
e
在双向链表中插入结点
Status ListInsert_Dul(DuLinklist &L,int i,ElemType e)
{
if(!(p=GetElem_DuL(L,i)))
return ERROR;
if(!(s=(DuLinkList)malloc(sizeof(DuLNode))))
if(!(p=GetElem_DuL(L,i)))
return ERROR; e=p->data; ① p->prior->next=p->next ; ② p->next->prior=p->prior; ③ free(p); return OK; }
p
a
b
c
在双向链表中删除结点
Status ListDelete_Dul(DuLinklist &L,int i,ElemType &e) {
相关文档
最新文档