如何从链表中删除节点?
这是我的代码:
void RemoveNode(Node * node, Node ** head) {
if (strcmp(node->state, (*(*head)->next).state) == 0) {
Node * temp = *head;
*head = (*head)->next;
free(temp);
return;
}
Node * current = (*head)->next;
Node * previous = *head;
while (current != NULL && previous != NULL) {
if (strcmp(node->state, (*current->next).state) == 0) {
Node * temp = current;
previous->next = current->next;
free(temp);
return;
}
current = current->next;
previous = previous->next;
}
return;
}
但我不断收到段错误。
我觉得我在做一些愚蠢的事情......有什么想法吗?