Delete duplicate-value nodes from a sorted linked list

Sort by

recency

|

910 Discussions

|

  • + 0 comments
    SinglyLinkedListNode* removeDuplicates(SinglyLinkedListNode* llist) {
        SinglyLinkedListNode *current = llist, *prev = NULL ;
        
        while(current->next != 0){
            prev = current;
            current = current->next;
            if(prev->data == current->data){
                prev->next = current->next;
                current = prev;
            }
        }
        
        return llist;
    }
    
  • + 0 comments

    Hi There i am try to make a search box just link any one who can make me code like this .... thanks

    Source https://statesmd.com/specialties/

  • + 0 comments

    Hi There i am try to make a search box just link any one who can make me code like this .... thanks

  • + 0 comments
        SinglyLinkedListNode* temp1;
        temp1=llist;
        
        while(temp1!=nullptr&&temp1->next!=nullptr)
        {
            if(temp1->data==temp1->next->data)
            {
                temp1->next=temp1->next->next;
            }else
            {
                temp1=temp1->next;
            }
                
        }
        
        return llist;
    }
    
    
    
  • + 0 comments

    Here, my solution:

    SinglyLinkedListNode* removeDuplicates(SinglyLinkedListNode* llist) {
        SinglyLinkedListNode* prev;
        SinglyLinkedListNode* curr = llist;
        
        while(curr != NULL) {
            prev = curr;
            curr = curr->next;
            
            while(curr != NULL && curr->data == prev->data){
                prev->next = curr->next;
                curr = curr->next;
            }
        }
        
        return llist;
    }