return key % size;
}
void insert(HashTable* ht, int key, int value) {
int index = hash(key, ht->size);
Node* newNode = (Node*)malloc(sizeof(Node));
newNode->key = key;
newNode->value = value;
newNode->next = ht->table[index];
ht->table[index] = newNode;
}
int find(HashTable* ht, int key) {
int index = hash(key, ht->size);
Node* current = ht->table[index];
while(current != NULL) {
if(current->key == key) {
return current->value;
}
current = current->next;
}
return -1; // 未找到
}
void freeHashTable(HashTable* ht) {
for(int i = 0; i size; i++) {
Node* current = ht->table[i];
while(current != NULL) {
Node* temp = current;
current = current->next;
free(temp);
}
}
free(ht->table);
free(ht);
}
```
写完最后一个分号,林澈看着满页的代码,手微微发抖。
这已经不是“大一学生”的水平了。这是工作三年、写过几十万
本章未完,请点击下一页继续阅读!