remove duplicates from sorted linked list

Write a C program to remove duplicates from a sorted linked list.

Comments

  1. void remove_duplicates_from_sorted_list(struct node* head)
    {
    if(head->next==NULL)
    return;
    struct node* current=head->next;
    struct node* previous=head;

    while(current!=NULL)
    {
    if(current->data==previous->data)
    {
    previous->next=current->next;
    delete(current);
    current=previous->next;
    }
    else
    {
    previous=current;
    current=current->next;
    }
    }


    }

    ReplyDelete

Post a Comment

Popular posts from this blog