mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
Several bug fixes.
This commit is contained in:
@ -13,7 +13,7 @@ TreeNode *res[MAX_SIZE];
|
||||
int resSize = 0;
|
||||
|
||||
/* 前序遍历:例题一 */
|
||||
static void preOrder(TreeNode *root) {
|
||||
void preOrder(TreeNode *root) {
|
||||
if (root == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ typedef struct {
|
||||
Node **buckets; // 桶数组
|
||||
} HashMapChaining;
|
||||
|
||||
/* 构造方法 */
|
||||
/* 构造函数 */
|
||||
HashMapChaining *initHashMapChaining() {
|
||||
HashMapChaining *hashMap = (HashMapChaining *)malloc(sizeof(HashMapChaining));
|
||||
hashMap->size = 0;
|
||||
@ -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];
|
||||
|
||||
@ -25,7 +25,7 @@ typedef struct {
|
||||
// 函数声明
|
||||
void extend(HashMapOpenAddressing *hashMap);
|
||||
|
||||
/* 构造方法 */
|
||||
/* 构造函数 */
|
||||
HashMapOpenAddressing *newHashMapOpenAddressing() {
|
||||
HashMapOpenAddressing *hashMap = (HashMapOpenAddressing *)malloc(sizeof(HashMapOpenAddressing));
|
||||
hashMap->size = 0;
|
||||
@ -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];
|
||||
|
||||
@ -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);
|
||||
@ -155,7 +155,7 @@ int main() {
|
||||
free(res);
|
||||
|
||||
// 释放内存
|
||||
free(root);
|
||||
freeMemoryTree(root);
|
||||
free(abt);
|
||||
|
||||
return 0;
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user