So I have an abstract data type of a singly linked list, and my compiler is stuck when running this part of the test code.
test.removeDuplicates();
System.out.println("removeDuplicates() has been run, check following output for counts of 3");
test.print();
My method for removing duplicates from the given list is as below
public void removeDuplicates()
{
if (head == null) return;
Node iter = head;
while (iter != null)
{
Node currNode = iter;
while(currNode != null && currNode.next != null)
{
if(iter.value == currNode.next.value)
{
currNode.next = currNode.next.next;
nItem--;
}
currNode = currNode.next;
}
}
}
I thought this while while loop was looping through the whole list and taking duplicate values out by making pointers skip values to remove them.
apparently one of the while loops does not terminate, it seems my last value isn't getting a pointer to null, but I do not understand why.