Hashtable implementation doubt

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

            return;
        }
        prev=temp;
        temp=temp->next;
    }
}

after using this erase fn and then printing its giving output till that bucket at which bucket i am erasing something
whats the prblm in this fn

prev=temp line is not there without that also its giving wrong o/p

@deepakjumani09
You forgot to point prev to next->temp before return
Also please send code on CB IDE from next time