Remove duplicates from sorted LL

void removeDuplicates(struct node* head)
{
    struct node* current = head;
    struct node* next;
    if(current == NULL)
        return;
    while(current->next!= NULL)
    {
        if(current->data == current->next->data)
        {
        next=current->next->next;
        free(current->next);
        current->next=next;
        }
        else
        {
        current = current->next;
        }
    }
}

 Time Complexity: O(n)

Comments

Popular posts from this blog

Three mislabeled Jar

Difference between Macro And function