在单链表中删除指定结点的两种算法:
一般思想:
- 扫描单链表,定位指定结点位置;
- 由于删除此结点需运用到该结点与其前驱结点,需两个指针 q, p 分别指向它们;
算法一:在带表头的单链表中删除元素值为 e 的结点
int delete_withHead(Linklist head, ElemType e)
{
struct node *q, *p;
q = head;
p = head->next;
在单链表中删除指定结点的两种算法:
一般思想:
算法一:在带表头的单链表中删除元素值为 e 的结点
int delete_withHead(Linklist head, ElemType e)
{
struct node *q, *p;
q = head;
p = head->next;