linked_list/linked_list1.cpp
/* This function removes the duplicate value from a sorted linked list
   by using two extra pointer to trace the duplicate element in the linked list
 */
This function removes the duplicate value from a sorted linked list
by using two extra pointer to trace the duplicate element in the linked list
This function removes the duplicate value from a sorted linked list by using two extra pointer to trace the duplicate element in the linked list
void remove_duplicate()
{
    struct Node *p = first;
    struct Node *q = first -> next;
    while (q != NULL)
    {
        if (p->data != q->data)
        {
            p=q;
            q=q->next;
        }
        else
        {
            p->next = q->next;
            delete q;
            q = p->next;
        }
    }
}
void remove_duplicate ( ) { struct Node * p = first ; struct Node * q = first -> next ; while ( q != NULL ) { if ( p -> data != q -> data ) { p = q ; q = q -> next ; } else { p -> next = q -> next ; delete q ; q = p -> next ; } } }
This function removes the duplicate value from a sorted linked list
by using two extra pointer to trace the duplicate element in the linked list
This function removes the duplicate value from a sorted linked list by using two extra pointer to trace the duplicate element in the linked list
// point p to first node // point q to point next of the first node // do not stop until // check if prev data is equals to next data // if not : slide bothe the pointer // if yes // delete node q