Erase functionality for Hashtable


I have written the code for erase function of hashtable but its not working properly is there a problem?

When a node is deleted , it goes to delete the entire linked list in front of it as well. We need to move around some pointers in erase function to prevent other elements from getting deleted.
Modified erase function -

void erase(string key){
        int idx=hashfn(key);
        node*ptr=table[idx];
        if(ptr->key==key){
            table[idx]=ptr->next;
            ptr->next = NULL;
            delete (ptr);
            curr_size--;
            return;
        }
        while(ptr->next!=NULL){
            if(ptr->next->key==key){
                node*temp=ptr->next;
                ptr->next=temp->next;
                temp->next = NULL;
                delete (temp);
                return;
            }
            ptr=ptr->next;
        }
        return;
    }

Hello @aryamaan1011,

As you have reopened the doubt, may i know what else do you wanna know?

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.