At the end of the list,
temp->next
will be
null
to indicate the end of the list.
So this code:
if(temp!=NULL && temp->next->data==curr->data)
will always fail for the last item as the next item doesn't exist.
Frankly, I'm not at all sure what
temp->next->data==curr->data
is supposed to be checking for, so I can't suggest a fix. I'd go back to the original instructions and check that part fairly carefully.