单链表插入和删除一个节点的伪代码算法

#单链表插入和删除一个节点的代码算法

单链表插入一个节点

Write 'a1 a2 a3 ... ai-1 ai+1 ... an-1 an'
Read SingleLinkList
Set ai-1 as node P
Set ai+1 as node Q(#P——>next == Q)
Set ai as node t
Set P——>next to t
Set t——>next to Q

单链表删除一个节点

Write 'a1 a2 a3 ... ai-1 ai+1 ... an-1 an'
Read SingleLinkList
Set ai-1 as node P
Set ai as node t
Set ai+1 as node Q(#P——>next == t, t——>next == Q)
Set P——>next = Q
python的实现

posted @ 2021-11-09 21:03  20211409赵枢博  阅读(80)  评论(0编辑  收藏  举报