对给定的带头结点的单链表L,编写一个删除L中值为X的结点的直接前驱结点的算法

2024-11-23 11:08:11
推荐回答(1个)
回答1:

DeleteNode( Node* L, int x)
{
Node* p,q,r;
p = q = r = L;
while(p->next ! = NULL)
{
p = p ->next;
if(p->data == x)
break;
r = q;
q = p;
}
delete q;
r->next = p;
}