6. Write a function in pseudocode named removeDuplicates(), which takes a singly
ID: 3747638 • Letter: 6
Question
6. Write a function in pseudocode named removeDuplicates(), which takes a singly linked list sorted in increasing order and deletes any duplicate nodes from the list. The list should only be traversed once and the routine should not call any other routine. For example if the linked list is 11->11->11->21->43->43->60 then removeDuplicates() should convert the list to 11-21->43->60. Input: the head node of the linked list Output: Your function should return a pointer to the head of linked list with no duplicate element. [10 Points]Explanation / Answer
class Node // structure of a single linked list
{
Node next;
int data;
Node(int value) // constructor for assigning default values
{
data=value;
next=null;
}
}
Node head; // head of the given linked list
Node removeDuplicates(Node* head)
{
Node temp = head; // initial pointer to head of the linked list
Node p; // temporary pointer
if (temp == null) // if list is empty
return;
while (temp.next != null) // iterating till end of the list
{
if (temp.data == temp.next.data) // if duplicates occurs
p = temp.next.next; // put next block to dulicate block in the temorary pointer
temp.next=null; // remove duplicate block
temp.next = p; // put next block to dulicate block in the list and check again
}
else
temp = temp.next;
}
return temp;
}
Hey , Really sorry , i didn't notice about language what you have stated here, sorry for the inconvenience.. noow i have edited the solution and check again please..if you get satisfied with the new solution , kindly vote accordingly..Sorry again..Please check the solution again..
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.