遍历链表并释放每个节点的内存空间,然后将指针赋为 NULL。示例代码如下:
void free_linked_list(Node* head) { Node* current = head; Node* next; while (current != NULL) { next = current->next; free(current); current = next; } head = NULL; }