Given a sorted linked list (elements are sorted in ascending order). Eliminate duplicates from the given LL, such that output LL contains only unique elements.
Input format: Linked list elements (separated by space and terminated by 1)
Sample Input 1 :
1 2 3 3 3 4 4 5 5 5 7 -1
Sample Output 1 :
1 2 3 4 5 7
Description:
In this question, we are given a sorted linked list with duplicate elements in it. Our task is to remove the duplicate nodes of the linked list. Since the list is sorted, the duplicate elements will be present in consecutive orders, that makes the work a lot easier.
Example:
Lets the list be:
1->2->3->3->4->4->4->NULL
The modified list will be:
1->2->3->4->NULL
C++ Code:
Output