Algorithm
1. Take two loops say loop outer and loop inner.
2. Run the outer loop from start to end and picks one element on each iteration.
3. Inner loop loop compares the picked element with rest of the elements.
Assume you Linklist node is looking like this
struct node
{
int data;
struct node *next;
};
Sample Code
void remove_duplicates(struct node *start)
{
struct node *ptr1, *ptr2, *dup;
ptr1 = start;
/* Outer Loop */
while(ptr1 != NULL && ptr1->next != NULL)
{
ptr2 = ptr1;
/* Inner Loop - Compare the picked element with rest of the elements */
while(ptr2->next != NULL)
{
if(ptr1->data == ptr2->next->data)
{
/* Duplicate - Delete the node */
dup = ptr2->next;
ptr2->next = ptr2->next->next;
free(dup);
}
else
{
ptr2 = ptr2->next;
}
}
ptr1 = ptr1->next;
}
}