Delete duplicate value nodes from a sorted linked list Solution
Problem Statement
You're given the pointer to the head node of a sorted linked list, where the data in the nodes is in ascending order. Delete as few nodes as possible so that the list does not contain any value more than once. The given head pointer may be null indicating that the list is empty.
Source code:
/*
Remove all duplicate elements from a sorted linked list
Node is defined as
struct Node
{
int data;
struct Node *next;
}
*/
Node* RemoveDuplicates(Node *head)
{
// This is a "method-only" submission.
// You only need to complete this method.
Node *cur = head;
while(cur->next!=NULL){
if(cur->data == cur->next->data)
cur->next = cur->next->next;
else
cur = cur->next;
}
return head;
}
Thank you, I had been looking for some online reference to be used in my Java training and your work really helped me.
ReplyDeleteJ2EE Training in Chennai | J2EE Training in Chennai | J2EE Training in Chennai
you are a great master! thankd for advice! I appreciate this. To enrich your vocabulary,visit research paper editing service - edit-ing.services, you won't regret! this site is a real miracle!
ReplyDeletehttps://goo.gl/WUYHgA
ReplyDeleteMaybe this is better, sir.
This comment has been removed by the author.
ReplyDeleteIt is so good to read a new article.
ReplyDeletejava interview questions and answers
selenium interview questions and answers
digital marketing interview questions and answers
hadoop interview questions and answers
oracle interview questions
data science interview questions and answers
Most helpful blog! It is the greatest comprehensive updates about this topic and Thank you for your sharing with us..!
ReplyDeleteAutomation Anywhere Training in Chennai
Automation Anywhere Online Training
VMware Training in Chennai
VMware Course in Bangalore
Automation Anyware Online Course