SinglyLinkedListNode* removeDuplicates(SinglyLinkedListNode* llist) {
SinglyLinkedListNode *third,*last,*t=llist;
third=last=llist;
int num=llist->data;
while(t!=NULL){
if(t->data == num){
t=t->next;
}
else {
num=t->data;
last->next = t;
last=t;
last->next=NULL;
t=t->next;
}
}
return third;
}
Removing duplicates in sorted (ascnding order) Singly linked list. I am using variable num to store the distinct node values. There are two pointers named third and last for the new LL without duplicates.Third will be the head of new LL and last will point to last node of LL. Assume in the line return third ; will return the new LL. I am getting output as 1 2 when I pass original LL as 1 2 2 3 4. WHY?