Hey everyone...
Well I am sorting items based upon a number.
My first case is if tail == null, if so that the first element to be added in the list.
My second case is if the element I want to add number is greater than the tail. If so I will set that element as the new tail.
My third case if where I get the infinite loop.
Okay, the first element(a Node)'s data is 5, then new number I want to add to the list is 4 .
while(info.compareTo(curr.getData()) < 0)
{
curr= curr.getNext();
}
So 5, points backs to itself right now.
It will go into the loop and then into the compare method.
Is 4 > 5? No, return -1
is -1 < 0 True
currr = curr.getNext() points back to 5(Since its circular)
Loop
Is 4 > 5? No, return -1
is -1 < 0 True
currr = curr.getNext() points back to 5(Since its circular)
Loop
Is 4 > 5? No, return -1
is -1 < 0 True
currr = curr.getNext() points back to 5(Since its circular)
Loop
Is 4 > 5? No, return -1
is -1 < 0 True
currr = curr.getNext() points back to 5(Since its circular)
Loop
Is 4 > 5? No, return -1
is -1 < 0 True
currr = curr.getNext() points back to 5(Since its circular)
Loop
And so on.........................
I ran through the debugger three times before I realized it.
Any help?