void erase(string key){//?
int idx = hashfn(key);
Node*temp = table[idx];
while(temp != NULL){
if(temp->key==key){
delete temp;
}
temp = temp->next;;
}
}
Erase function not working fine
your function is not correct
Correct Way
void erase(string key){
int idx=hashfun(key);
Node<T>*temp=table[idx];
Node<T>*prev=NULL;
while(temp){
if(temp->key==key){
if(prev)prev->next=temp->next;
else table[idx]=temp->next;
temp->next=NULL;
delete temp;
}
prev=temp;
temp=temp->next;
}
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.