I need to create a function that deletes the duplicates from a linked list this , I think looks right but it causes an application error saying the memory at a certain location could not be read
void delrep (node *&head)
{ node *previous = head;
for (node *head2 = head ; head2->link != NULL;head2=head2->link)
{
for (node *compare =head->link;compare ->link !=NULL; compare=compare ->link)
{
if ( compare ->data == head2->data)
{
previous->link = compare->link;
delete compare;
if(compare->link == NULL)
break;
}
previous = compare;
}
}
}
Any ideas whats wrong with it?