mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
Free memory after removing
a node from a LinkedList or TreeNode.
This commit is contained in:
@@ -311,7 +311,10 @@ comments: true
|
||||
/* 出栈 */
|
||||
int pop() {
|
||||
int num = top();
|
||||
ListNode *tmp = stackTop;
|
||||
stackTop = stackTop->next;
|
||||
// 释放内存
|
||||
delete tmp;
|
||||
stkSize--;
|
||||
return num;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user