mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-07 06:44:57 +08:00
Add destructors to the C++ codes.
This commit is contained in:
@ -17,6 +17,10 @@ public:
|
||||
root = buildTree(nums, 0, nums.size() - 1); // 构建二叉搜索树
|
||||
}
|
||||
|
||||
~BinarySearchTree() {
|
||||
freeMemoryTree(root);
|
||||
}
|
||||
|
||||
/* 获取二叉树根结点 */
|
||||
TreeNode* getRoot() {
|
||||
return root;
|
||||
@ -152,5 +156,8 @@ int main() {
|
||||
cout << endl << "删除结点 4 后,二叉树为\n" << endl;
|
||||
PrintUtil::printTree(bst->getRoot());
|
||||
|
||||
// 释放内存
|
||||
delete bst;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user