This commit is contained in:
krahets
2024-11-25 19:12:22 +08:00
parent ff8738ab95
commit 97733f1a7d
13 changed files with 141 additions and 215 deletions

View File

@@ -490,12 +490,12 @@ comments: true
}
/* 哈希表元素插入 */
void insert(HashTable *h, int key, int val) {
HashTable *t = find(h, key);
void insert(HashTable **h, int key, int val) {
HashTable *t = find(*h, key);
if (t == NULL) {
HashTable *tmp = malloc(sizeof(HashTable));
tmp->key = key, tmp->val = val;
HASH_ADD_INT(h, key, tmp);
HASH_ADD_INT(*h, key, tmp);
} else {
t->val = val;
}
@@ -512,7 +512,7 @@ comments: true
*returnSize = 2;
return res;
}
insert(hashtable, nums[i], i);
insert(&hashtable, nums[i], i);
}
*returnSize = 0;
return NULL;