mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-24 02:21:30 +08:00
Add space_complexit under C and fix memory leak under CPP (#456)
* 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) * fix(codes/cpp): Fix memory leaks: replace pointers with local variables, no need to manage memory * fix(codes/cpp): Fix memory leaks: no delete * fix(codes/cpp): Fix memory leaks: Add destructor ~ArrayHashMap() * Update PrintUtil.hpp * feat(codes/c): Add three-party hash implementation * feat(codes/c): Add freeMemoryTree in tree_node.h * feat(codes/c): Add space_complexity.c * styles(codes/c): Modify format * feat(codes/cpp): Undo a previous delete, there is no memory leak here * Update array_hash_map.cpp * Update include.h --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
add_executable(include
|
||||
include_test.c
|
||||
include.h print_util.h
|
||||
list_node.h tree_node.h)
|
||||
list_node.h tree_node.h
|
||||
uthash.h)
|
||||
@@ -18,6 +18,9 @@
|
||||
#include "tree_node.h"
|
||||
#include "print_util.h"
|
||||
|
||||
// hash table lib
|
||||
#include "uthash.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
@@ -124,6 +124,15 @@ int *treeToArr(TreeNode *root) {
|
||||
return arr;
|
||||
}
|
||||
|
||||
/* Free the memory allocated to a tree */
|
||||
void freeMemoryTree(TreeNode *root) {
|
||||
if (root == NULL)
|
||||
return;
|
||||
freeMemoryTree(root->left);
|
||||
freeMemoryTree(root->right);
|
||||
// 释放内存
|
||||
free(root);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
1140
codes/c/include/uthash.h
Normal file
1140
codes/c/include/uthash.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user