mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +08:00
Free memory after removing
a node from a LinkedList or TreeNode.
This commit is contained in:
@ -21,6 +21,8 @@ void remove(ListNode* n0) {
|
||||
ListNode* P = n0->next;
|
||||
ListNode* n1 = P->next;
|
||||
n0->next = n1;
|
||||
// 释放内存
|
||||
delete P;
|
||||
}
|
||||
|
||||
/* 访问链表中索引为 index 的结点 */
|
||||
|
||||
Reference in New Issue
Block a user