How to remove duplicates from inked list which repeats double number of times(C++)? : I've been trying to create own linked list class on C++. My task is remove all nodes which data repeats double number of times in list and store only one node if data repeats odd number of times. I've written function removeDuplicates(), but my program crashes when i try to use the function. Implementation here:

    void LinkedList::removeDuplicates(){
        Node *ptr1, *ptr2, *dup, *toDel;
        int counter = 1;
        ptr1 = top;
        while(ptr1 != NULL && ptr1->next != NULL){
            ptr2 = ptr1;
            while(ptr2->next != NULL){
                if(ptr1->name == ptr2->next->name){
                    dup = ptr2->next;
                    ptr2->next = ptr2->next->next;
                    delete dup;
                    counter++;
                } else {
                   ptr2 = ptr2->next;
                }
            }
            if(counter % 2 == 0){
                toDel = ptr1;
                ptr1->next = ptr1->next->next;
                ptr1 = ptr1->next;
                delete toDel;
            }else{
                ptr1 = ptr1->next;
            }
        }
    }
