Skip to content

Commit

Permalink
Several bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
krahets committed Oct 28, 2023
1 parent c37f098 commit db5d1d2
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TreeNode *res[MAX_SIZE];
int resSize = 0;

/* 前序遍历:例题一 */
static void preOrder(TreeNode *root) {
void preOrder(TreeNode *root) {
if (root == NULL) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TreeNode *res[MAX_RES_SIZE][MAX_SIZE];
int pathSize = 0, resSize = 0;

/* 前序遍历:例题二 */
static void preOrder(TreeNode *root) {
void preOrder(TreeNode *root) {
if (root == NULL) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions codes/c/chapter_hashing/hash_map_chaining.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef struct {
Node **buckets; // 桶数组
} HashMapChaining;

/* 构造方法 */
/* 构造函数 */
HashMapChaining *initHashMapChaining() {
HashMapChaining *hashMap = (HashMapChaining *)malloc(sizeof(HashMapChaining));
hashMap->size = 0;
Expand All @@ -46,7 +46,7 @@ HashMapChaining *initHashMapChaining() {
return hashMap;
}

/* 析构方法 */
/* 析构函数 */
void freeHashMapChaining(HashMapChaining *hashMap) {
for (int i = 0; i < hashMap->capacity; i++) {
Node *cur = hashMap->buckets[i];
Expand Down
4 changes: 2 additions & 2 deletions codes/c/chapter_hashing/hash_map_open_addressing.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ typedef struct {
// 函数声明
void extend(HashMapOpenAddressing *hashMap);

/* 构造方法 */
/* 构造函数 */
HashMapOpenAddressing *newHashMapOpenAddressing() {
HashMapOpenAddressing *hashMap = (HashMapOpenAddressing *)malloc(sizeof(HashMapOpenAddressing));
hashMap->size = 0;
Expand All @@ -40,7 +40,7 @@ HashMapOpenAddressing *newHashMapOpenAddressing() {
return hashMap;
}

/* 析构方法 */
/* 析构函数 */
void delHashMapOpenAddressing(HashMapOpenAddressing *hashMap) {
for (int i = 0; i < hashMap->capacity; i++) {
Pair *pair = hashMap->buckets[i];
Expand Down
6 changes: 3 additions & 3 deletions codes/c/chapter_tree/array_binary_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

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

/* 数组表示下的二叉树结构 */
/* 数组表示下的二叉树结构体 */
typedef struct {
int *tree;
int size;
} ArrayBinaryTree;

/* 构造方法 */
/* 构造函数 */
ArrayBinaryTree *createArrayBinaryTree(int *arr, int arrSize) {
ArrayBinaryTree *abt = (ArrayBinaryTree *)malloc(sizeof(ArrayBinaryTree));
abt->tree = malloc(sizeof(int) * arrSize);
Expand Down Expand Up @@ -155,7 +155,7 @@ int main() {
free(res);

// 释放内存
free(root);
freeMemoryTree(root);
free(abt);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion codes/c/utils/list_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct ListNode {

/* 构造函数,初始化一个新节点 */
ListNode *newListNode(int val) {
ListNode *node, *next;
ListNode *node;
node = (ListNode *)malloc(sizeof(ListNode));
node->val = val;
node->next = NULL;
Expand Down
2 changes: 1 addition & 1 deletion codes/dart/utils/list_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ListNode {
ListNode(this.val, [this.next]);
}

/* Generate a linked list with a vector */
/* Generate a linked list with a list */
ListNode? listToLinkedList(List<int> list) {
ListNode dum = ListNode(0);
ListNode? head = dum;
Expand Down
7 changes: 2 additions & 5 deletions codes/python/chapter_graph/graph_adjacency_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@
class GraphAdjMat:
"""基于邻接矩阵实现的无向图类"""

# 顶点列表,元素代表“顶点值”,索引代表“顶点索引”
vertices: list[int] = []
# 邻接矩阵,行列索引对应“顶点索引”
adj_mat: list[list[int]] = []

def __init__(self, vertices: list[int], edges: list[list[int]]):
"""构造方法"""
# 顶点列表,元素代表“顶点值”,索引代表“顶点索引”
self.vertices: list[int] = []
# 邻接矩阵,行列索引对应“顶点索引”
self.adj_mat: list[list[int]] = []
# 添加顶点
for val in vertices:
Expand Down
2 changes: 1 addition & 1 deletion codes/swift/chapter_heap/top_k.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import utils

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

0 comments on commit db5d1d2

Please sign in to comment.