代码:
struct Test *deleteNode(struct Test *head,int data)
{
struct Test *p=head;
if(p->data=data){
head=head->next;
free(p);//释放内存,但是不可以释放普通变量出u来的指针,只可以释放malloc出来的野指针,在动态创建时
return head;
}//当要删除的链表节点为头节点时,运用上式代码。
while(p->next!=NULL){
if(p->next->data==data){
struct Test *tmp=p;
p->next=p->next->next;
free(tmp);
return head;
}
p=p->next;
}
return head;
}