Remove duplicate from sorted linked list

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

Leave a comment