Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug fixes for array_hash_map.c and counting_sort.c #968

Merged
merged 56 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
cd1cfe9
fix(codes/cpp): Memory leak fix: the space was not freed when pop rem…
Gonglja Mar 18, 2023
53b02c2
Merge branch 'krahets:main' into master
Gonglja Mar 18, 2023
e6efb72
fix(codes/cpp): Fix access error when printArray(arr, 0)
Gonglja Mar 20, 2023
2f08dcb
Merge remote-tracking branch 'origin/master'
Gonglja Mar 20, 2023
68f53fd
Merge branch 'krahets:main' into master
Gonglja Mar 20, 2023
b55231a
Update PrintUtil.hpp
krahets Mar 20, 2023
5abf181
Merge branch 'main' into master
krahets Mar 20, 2023
69e7973
Merge branch 'krahets:main' into master
Gonglja Mar 20, 2023
c1a6168
Merge branch 'krahets:main' into master
Gonglja Apr 15, 2023
d875d23
Merge branch 'krahets:main' into master
Gonglja Apr 15, 2023
e9a7238
fix(codes/c): Fix some errors of cmake build
Gonglja Apr 15, 2023
55fe194
feat(codes/c): Add hashing_search.c
Gonglja Apr 15, 2023
75b838e
Merge branch 'krahets:main' into master
Gonglja Apr 17, 2023
8fef6a6
Merge branch 'krahets:main' into master
Gonglja Apr 18, 2023
c659519
Merge branch 'krahets:main' into main
Gonglja Apr 21, 2023
d7e582b
styles(codes/c): Modify function description
Gonglja Apr 21, 2023
1fa0e58
styles(codes/c): Modify binary_search.c code style
Gonglja Apr 21, 2023
903d6bd
Merge branch 'krahets:main' into main
Gonglja Apr 22, 2023
a266334
Merge branch 'krahets:main' into main
Gonglja May 7, 2023
11ce50f
fix(codes/c): Fix the problem in binary_tree_bfs.c and the problem th…
Gonglja May 8, 2023
f4d85c6
Merge branch 'krahets:main' into main
Gonglja May 10, 2023
2d79565
Merge branch 'krahets:main' into main
Gonglja May 28, 2023
0ef4f41
feat: Add preorder_traversal_i_compact.c
Gonglja May 28, 2023
8b44c21
Merge remote-tracking branch 'refs/remotes/origin/main'
Gonglja May 28, 2023
5034e02
feat(codes/c): Add head_sort.c
Gonglja May 30, 2023
af533b0
feat(codes/c): Add bucket_sort.c
Gonglja May 30, 2023
265de38
Merge branch 'krahets:main' into main
Gonglja May 30, 2023
bd2df0b
feat(codes/c): Add binary_search_edge.c
Gonglja May 30, 2023
b68db28
fix(codes/c): Add programs that are not managed by cmake (c code)
Gonglja May 30, 2023
728fc23
Merge branches 'main' and 'main' of github.com:Gonglja/hello-algo
Gonglja May 30, 2023
0892aa9
feat(codes/c): Add selection_sort.c
Gonglja May 30, 2023
47ce2d2
style(codes/c): Change swap in selection_sort.c to `selectionSort`
Gonglja May 31, 2023
dc4c359
styles(codes/c): Change style.
Gonglja May 31, 2023
cfe680e
fix(codes/c): Fix some formatting errors and temporarily remove backt…
Gonglja Jun 1, 2023
b813e68
Merge remote-tracking branch 'upstream/main'
Gonglja Jul 10, 2023
3dfc688
feat(codes/c): First remove chapter_backtracking in cmakelists.txt
Gonglja Jul 24, 2023
919a270
Merge branch 'krahets:main' into main
Gonglja Jul 29, 2023
e55c173
Merge branch 'krahets:main' into main
Gonglja Jul 29, 2023
22464a3
fix(codes/c): Fix space_complexity.c build error.
Gonglja Jul 29, 2023
18f6328
feat(codes/c): Add array_binary_tree.c
Gonglja Jul 29, 2023
c9753ec
feat(code/c): Update push_back and pop_back in vector.h
Gonglja Jul 29, 2023
ef8df02
Merge branch 'krahets:main' into main
Gonglja Jul 29, 2023
d3f7f9f
styles(codes/c): Adjust format.
Gonglja Jul 31, 2023
1aa166d
Merge branch 'main' of github.com:Gonglja/hello-algo
Gonglja Jul 31, 2023
e62fce3
Merge branch 'main' into main
krahets Aug 3, 2023
92fb329
Merge remote-tracking branch 'upstream/main'
Gonglja Sep 1, 2023
c74f7b8
Merge branch 'krahets:main' into main
Gonglja Sep 8, 2023
b027731
feat(codes/c): Add `interation.c ` `recursion.c` `simple_hash.c` `bin…
Gonglja Sep 9, 2023
17ff669
Merge branch 'krahets:main' into main
Gonglja Sep 10, 2023
4940590
Merge branch 'krahets:main' into main
Gonglja Sep 12, 2023
edc31cc
fix(mylist.c): Fix `insert` function in `mylist.c`
Gonglja Sep 12, 2023
94b7ee6
feat(codes/c): Add binary_search_recur.c
Gonglja Sep 19, 2023
10bad07
Merge branch 'upstream'
Gonglja Oct 24, 2023
54b3a22
Merge branch 'krahets:main' into main
Gonglja Oct 28, 2023
0365bc7
Merge branch 'krahets:main' into main
Gonglja Nov 26, 2023
0281951
fix(codes/c): Bug fixes in discussion
Gonglja Nov 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codes/c/chapter_hashing/array_hash_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void pairSet(ArrayHashMap *hmap, MapSet *set) {
for (i = 0; i < HASHTABLE_CAPACITY; i++) {
if (hmap->buckets[i] != NULL) {
entries[index].key = hmap->buckets[i]->key;
entries[index].val = malloc(strlen(hmap->buckets[i]->val + 1));
entries[index].val = malloc(strlen(hmap->buckets[i]->val) + 1);
strcpy(entries[index].val, hmap->buckets[i]->val);
index++;
}
Expand Down
10 changes: 8 additions & 2 deletions codes/c/chapter_sorting/counting_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void countingSortNaive(int nums[], int size) {
}
// 2. 统计各数字的出现次数
// counter[num] 代表 num 的出现次数
int *counter = malloc(sizeof(int) * m);
int *counter = calloc(m, sizeof(int));
for (int i = 0; i < size; i++) {
counter[nums[i]]++;
}
Expand All @@ -29,6 +29,9 @@ void countingSortNaive(int nums[], int size) {
nums[i] = num;
}
}

// 4. 释放内存
free(counter);
}

/* 计数排序 */
Expand All @@ -43,7 +46,7 @@ void countingSort(int nums[], int size) {
}
// 2. 统计各数字的出现次数
// counter[num] 代表 num 的出现次数
int *counter = malloc(sizeof(int) * m);
int *counter = calloc(m, sizeof(int));
for (int i = 0; i < size; i++) {
counter[nums[i]]++;
}
Expand All @@ -62,6 +65,9 @@ void countingSort(int nums[], int size) {
}
// 使用结果数组 res 覆盖原数组 nums
memcpy(nums, res, size * sizeof(int));

// 5. 释放内存
free(counter);
}

/* Driver Code */
Expand Down