Add destructors to the C++ codes.

This commit is contained in:
Yudong Jin
2023-01-14 19:52:11 +08:00
parent 87acfc91ab
commit bb657f9517
19 changed files with 121 additions and 24 deletions

View File

@ -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;
}
}