当前位置:   article > 正文

双向链表的基本操作

双向链表的基本操作

已知P结点是某双向链表的中间结点:

1.在P结点后插入S结点

S->next = P->next;

P->next->prior = S;

S->prior = P;

P->next = S;

 

2.在P结点前插入S结点

S->prior = P->prior;

P->prior->next = S;

S->next = P;

P->prior = S;

3.删除P结点的直接后继节点

 

Q = P->next;

P->next = P->next->next;

P->next->prior = P;

free(Q);

4.删除P结点的直接前驱结点

Q = P->prior;

P->prior->next = P;

P->prior = P->prior->prior;

free(Q);

 

5.删除P结点

P->prior->next = P->next;

P->next->prior = P->prior;

free(P);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/952512
推荐阅读
相关标签
  

闽ICP备14008679号