图书馆的邀请与黑色的警告 (2/8)
bsp;{
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);
本章未完,请点击下一页继续阅读