Delete duplicate value nodes from a sorted linked list Solution

Delete duplicate value nodes from a sorted linked list Solution


Problem Statement

You're given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete as few nodes as possible so that the list does not contain any value more than once. The given head pointer may be null indicating that the list is empty.

Source code:

 /*  
  Remove all duplicate elements from a sorted linked list  
  Node is defined as   
  struct Node  
  {  
    int data;  
    struct Node *next;  
  }  
 */  
 Node* RemoveDuplicates(Node *head)  
 {  
  // This is a "method-only" submission.   
  // You only need to complete this method.   
   Node *cur = head;  
   while(cur->next!=NULL){  
     if(cur->data == cur->next->data)  
       cur->next = cur->next->next;   
     else  
     cur = cur->next;  
   }  
   return head;  
 }  

7 comments :

  1. Thank you, I had been looking for some online reference to be used in my Java training and your work really helped me.
    J2EE Training in Chennai | J2EE Training in Chennai | J2EE Training in Chennai

    ReplyDelete
  2. you are a great master! thankd for advice! I appreciate this. To enrich your vocabulary,visit research paper editing service - edit-ing.services, you won't regret! this site is a real miracle!

    ReplyDelete
  3. https://goo.gl/WUYHgA

    Maybe this is better, sir.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Top 10 Casino Apps - Casinoworld
    In this section we'll 1등 사이트 walk you through our selection https://tricktactoe.com/ of www.jtmhub.com top casino apps, https://octcasino.com/ and hopefully you'll find plenty of useful information on the top How do you use PayPal?Are there any deposit bonuses at your casino? gri-go.com

    ReplyDelete