yakg5000
New member
- Joined
- May 30, 2021
- Messages
- 2
- Programming Experience
- 3-5
Hey, I wrote the following code but there's something I miss since nothing changes the pointers of the list for some reason.
My idea in the method is to remove all duplicated nodes, so in 6 6 6 3 2 2 1, should be changed to 6 3 2 1
As mentioned nothing changes when I am changing the reference points.. So setting the next reference seem to not really change it..
Thanks.
My idea in the method is to remove all duplicated nodes, so in 6 6 6 3 2 2 1, should be changed to 6 3 2 1
As mentioned nothing changes when I am changing the reference points.. So setting the next reference seem to not really change it..
Thanks.
C#:
public int removeDuplicates(Node head)
{
Node current = head;
LinkedList result = new LinkedList();
while (current != null)
{
Node runner = current.next;
while (runner != null)
{
while (runner != null && runner.data == current.data)
{
runner = runner.next;
}
runner = runner.next;
}
result.AddLast(current.data);
current = current.next;
}
return result.count();
}
Last edited by a moderator: