How we will implement erase function in hashing?
How we will implement erase function in hashing?
code :-
void erase(string key){
int idx = hashFunc(key);
Node<T>* temp = table[idx];
Node<T>* prev = NULL;
while(temp != NULL){
if(temp->key == key){
if(prev){
prev->next = temp->next;
}
else{
table[idx] = temp->next;
}
temp->next = NULL;
delete temp;
return ;
}
prev = temp;
temp = temp->next;
}
}