mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-22 15:53:50 +08:00
Add destructors to the C++ codes.
This commit is contained in:
@ -48,3 +48,18 @@ ListNode* getListNode(ListNode *head, int val) {
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Free the memory allocated to a linked list
|
||||
*
|
||||
* @param cur
|
||||
*/
|
||||
void freeMemoryLinkedList(ListNode *cur) {
|
||||
// 释放内存
|
||||
ListNode *pre;
|
||||
while (cur != nullptr) {
|
||||
pre = cur;
|
||||
cur = cur->next;
|
||||
delete pre;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user