mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-13 11:09:48 +08:00
Fix the problem in binary_tree_bfs.c and the problem that the memory is not released. (#487)
* fix(codes/cpp): Memory leak fix: the space was not freed when pop removed the element. * fix(codes/cpp): Fix access error when printArray(arr, 0) * Update PrintUtil.hpp * fix(codes/c): Fix some errors of cmake build * feat(codes/c): Add hashing_search.c * styles(codes/c): Modify function description * styles(codes/c): Modify binary_search.c code style * fix(codes/c): Fix the problem in binary_tree_bfs.c and the problem that the memory is not released. --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -49,7 +49,7 @@ TreeNode *arrToTree(const int *arr, size_t size) {
|
||||
/* 根节点 */
|
||||
root = newTreeNode(arr[0]);
|
||||
/* 辅助队列 */
|
||||
queue = (TreeNode **)malloc(sizeof(TreeNode) * MAX_NODE_SIZE);
|
||||
queue = (TreeNode **)malloc(sizeof(TreeNode *) * MAX_NODE_SIZE);
|
||||
// 队列指针
|
||||
front = 0, rear = 0;
|
||||
// 将根节点放入队尾
|
||||
@@ -75,6 +75,8 @@ TreeNode *arrToTree(const int *arr, size_t size) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 释放辅助队列空间
|
||||
free(queue);
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user