In this code, I am not able to erase the key from the hash table…
Help Required
the link of my code ;
Erase fn in Hashtable
your erase function is not correct
correct one
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.