【发布时间】:2020-09-20 05:43:43
【问题描述】:
所以基本上我正在为linkedList 编写代码,但由于这里的代码,我不断收到内存泄漏。谁能帮我找出原因,并向我解释我做错了什么?
struct Node* deleteNode(int data, struct Node* head){
struct Node* current = head;
struct Node* previous = NULL;
if(head == NULL){
return NULL;
}
while(current->data != data){
if(current->next == NULL){
return NULL;
}else{
previous = current;
current = current->next;
}
}
if(current == head){
struct Node* temp = head;
head = head->next;
free(temp);
}else
{
previous->next = current->next;
}
current = NULL;
return head;
}
【问题讨论】:
标签: c memory-leaks linked-list