Delete duplicate-value nodes from a sorted linked list

  • + 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;
    }