code is at : “https://ide.codingblocks.com/s/681573”
I'm getting a segmentation fault in erase function
u can refer this @kartikey.rajput0071
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;
}
}
steps
- find the hasvalue corresponding to given key
- find the node which we have to delete and then delete that node
to delete node you also need prev pointer
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.