单链表的插入和删除

单链表插入

定义链表a=[a₁,a₂,a₃······ai-1,ai+1······an-1,an]
ai-1-->节点p,ai+1-->节点q(此时p->next = q)
设插入元素ai为节点x
p->next = x
x->next = q

单链表删除

定义列表a=[a₁,a₂,a₃······ai,ai+1······an-1,an]
ai-1节点-->p, ai节点-->t, ai+1节点-->q(此时p->next = t, t->next = q )
p->next = q->next
free (t)
posted @ 2022-10-22 15:59  20221304刘奕彤  阅读(35)  评论(0编辑  收藏  举报