Error in erase function

Kindly find the error in the erase function.

@sr30 hey in this while loop while(temp->next!=NULL)
{
if(temp->next->key==k)
{
node *temp2=temp->next;
temp->next=temp->next->next;
delete temp2;
return;
}
temp=temp->next;
}
use temp as current pointer instead of temp->next as it can happen ki dono delete wali value sath me ho also temp->next->next Null bhi ho skta hai uski wjah se runtime error bhi askti hai ,isi case me galti hai baki sab thek hai.

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.