1.扫描单链表依次判断
void Del_x(LinkList &L,ElemType x)
{
LNode *p=L->next,*q=L,*s;
while(p!=NULL)
{
if(p->data==x)
{
s=p;
p=p->next;
q->next=p;
free(s);
}
else
{
q=p;
p=p->next;
}
}
}
2.边扫描边重新建立链接
void Del_x(LinkList &L,ElemType x)
{
LNode *p=L->next,*r=L,*s;
while(p!=NULL)
{
if(p->data!=x)
{
r->next=p;
r=p;
p=p->next;
}
else
{
s=p;
p=p->next;
free(s);
}
}
r->next=NULL;
}