Skip to content

Commit db5d1d2

Browse files
committed
Several bug fixes.
1 parent c37f098 commit db5d1d2

File tree

9 files changed

+14
-17
lines changed

9 files changed

+14
-17
lines changed

codes/c/chapter_backtracking/preorder_traversal_i_compact.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ TreeNode *res[MAX_SIZE];
1313
int resSize = 0;
1414

1515
/* 前序遍历:例题一 */
16-
static void preOrder(TreeNode *root) {
16+
void preOrder(TreeNode *root) {
1717
if (root == NULL) {
1818
return;
1919
}

codes/c/chapter_backtracking/preorder_traversal_ii_compact.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ TreeNode *res[MAX_RES_SIZE][MAX_SIZE];
1515
int pathSize = 0, resSize = 0;
1616

1717
/* 前序遍历:例题二 */
18-
static void preOrder(TreeNode *root) {
18+
void preOrder(TreeNode *root) {
1919
if (root == NULL) {
2020
return;
2121
}

codes/c/chapter_hashing/hash_map_chaining.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ typedef struct {
3232
Node **buckets; // 桶数组
3333
} HashMapChaining;
3434

35-
/* 构造方法 */
35+
/* 构造函数 */
3636
HashMapChaining *initHashMapChaining() {
3737
HashMapChaining *hashMap = (HashMapChaining *)malloc(sizeof(HashMapChaining));
3838
hashMap->size = 0;
@@ -46,7 +46,7 @@ HashMapChaining *initHashMapChaining() {
4646
return hashMap;
4747
}
4848

49-
/* 析构方法 */
49+
/* 析构函数 */
5050
void freeHashMapChaining(HashMapChaining *hashMap) {
5151
for (int i = 0; i < hashMap->capacity; i++) {
5252
Node *cur = hashMap->buckets[i];

codes/c/chapter_hashing/hash_map_open_addressing.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ typedef struct {
2525
// 函数声明
2626
void extend(HashMapOpenAddressing *hashMap);
2727

28-
/* 构造方法 */
28+
/* 构造函数 */
2929
HashMapOpenAddressing *newHashMapOpenAddressing() {
3030
HashMapOpenAddressing *hashMap = (HashMapOpenAddressing *)malloc(sizeof(HashMapOpenAddressing));
3131
hashMap->size = 0;
@@ -40,7 +40,7 @@ HashMapOpenAddressing *newHashMapOpenAddressing() {
4040
return hashMap;
4141
}
4242

43-
/* 析构方法 */
43+
/* 析构函数 */
4444
void delHashMapOpenAddressing(HashMapOpenAddressing *hashMap) {
4545
for (int i = 0; i < hashMap->capacity; i++) {
4646
Pair *pair = hashMap->buckets[i];

codes/c/chapter_tree/array_binary_tree.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
#include "../utils/common.h"
88

9-
/* 数组表示下的二叉树结构 */
9+
/* 数组表示下的二叉树结构体 */
1010
typedef struct {
1111
int *tree;
1212
int size;
1313
} ArrayBinaryTree;
1414

15-
/* 构造方法 */
15+
/* 构造函数 */
1616
ArrayBinaryTree *createArrayBinaryTree(int *arr, int arrSize) {
1717
ArrayBinaryTree *abt = (ArrayBinaryTree *)malloc(sizeof(ArrayBinaryTree));
1818
abt->tree = malloc(sizeof(int) * arrSize);
@@ -155,7 +155,7 @@ int main() {
155155
free(res);
156156

157157
// 释放内存
158-
free(root);
158+
freeMemoryTree(root);
159159
free(abt);
160160

161161
return 0;

codes/c/utils/list_node.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ typedef struct ListNode {
1919

2020
/* 构造函数,初始化一个新节点 */
2121
ListNode *newListNode(int val) {
22-
ListNode *node, *next;
22+
ListNode *node;
2323
node = (ListNode *)malloc(sizeof(ListNode));
2424
node->val = val;
2525
node->next = NULL;

codes/dart/utils/list_node.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ListNode {
1212
ListNode(this.val, [this.next]);
1313
}
1414

15-
/* Generate a linked list with a vector */
15+
/* Generate a linked list with a list */
1616
ListNode? listToLinkedList(List<int> list) {
1717
ListNode dum = ListNode(0);
1818
ListNode? head = dum;

codes/python/chapter_graph/graph_adjacency_matrix.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414
class GraphAdjMat:
1515
"""基于邻接矩阵实现的无向图类"""
1616

17-
# 顶点列表,元素代表“顶点值”,索引代表“顶点索引”
18-
vertices: list[int] = []
19-
# 邻接矩阵,行列索引对应“顶点索引”
20-
adj_mat: list[list[int]] = []
21-
2217
def __init__(self, vertices: list[int], edges: list[list[int]]):
2318
"""构造方法"""
19+
# 顶点列表,元素代表“顶点值”,索引代表“顶点索引”
2420
self.vertices: list[int] = []
21+
# 邻接矩阵,行列索引对应“顶点索引”
2522
self.adj_mat: list[list[int]] = []
2623
# 添加顶点
2724
for val in vertices:

codes/swift/chapter_heap/top_k.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import utils
99

1010
/* 基于堆查找数组中最大的 k 个元素 */
1111
func topKHeap(nums: [Int], k: Int) -> [Int] {
12-
// 将数组的前 k 个元素入堆
12+
// 初始化一个小顶堆,并将前 k 个元素建堆
1313
var heap = Heap(nums.prefix(k))
1414
// 从第 k+1 个元素开始,保持堆的长度为 k
1515
for i in stride(from: k, to: nums.count, by: 1) {

0 commit comments

Comments
 (0)