Complete the code to initialize the head of the linked list to NULL in the hash table.
hashTable->buckets[index].head = [1];In chaining, each bucket's linked list head should start as NULL to indicate it is empty.
Complete the code to create a new node and assign the key value in the chaining linked list.
newNode = (Node*)malloc(sizeof(Node));
newNode->key = [1];The new node's key field should be assigned the key passed to the insert function.
Fix the error in the code to insert the new node at the beginning of the linked list for chaining.
newNode->next = [1];
hashTable->buckets[index].head = newNode;The new node's next pointer should point to the current head of the list before updating the head.
Fill both blanks to complete the search function that traverses the linked list to find a key.
Node* current = hashTable->buckets[index].head; while (current != [1]) { if (current->key == [2]) { return current; } current = current->next; }
The loop continues until current is NULL, and compares current->key with the search key.
Fill all three blanks to complete the delete function that removes a node with a given key from the chain.
Node* current = hashTable->buckets[index].head; Node* prev = [1]; while (current != NULL && current->key != [2]) { prev = current; current = current->next; } if (current == NULL) return; if (prev == NULL) { hashTable->buckets[index].head = current->next; } else { prev->next = [3]; } free(current);
Initially, prev is NULL. We look for the node with the key. If prev is NULL, we update head. Otherwise, prev->next skips the deleted node.
