Given a sorted doubly linked list containing n nodes. The problem is to remove duplicate nodes from the given list.
removeDuplicates(head_ref, x) if head_ref == NULL return Initialize current = head_ref while current->next != NULL if current->data == current->next->data deleteNode(head_ref, current->next) else current = current->next
The algorithm for deleteNode(head_ref, current) (which deletes the node using the pointer to the node) is discussed in this post.
Original Doubly linked list: 4 4 4 4 6 8 8 10 12 12 Doubly linked list after removing duplicates: 4 6 8 10 12
Time Complexity: O(n)
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.