i tried to write a method that sort a linked list. this is java training for me.
the method should get a linked list with values and sort it with selection sort. but not the usual selection sort, but selection sort that find the biggest number and put it in the start of the linked list. until the list is sorted.
i tried follow the debugger but, i cant really understand what i did wrong.
this is what i tired:
public IntList selectionSort()
{
IntNode tempMax = _head;
IntNode current = _head;
IntNode fromHere = null;
IntNode toHere = _head;
IntNode prev = null;
while(toHere != null)
{
current = toHere;
tempMax = toHere;
while (current != null)
{
if (current.getNext() != null && current.getNext().getValue() > tempMax.getValue())
{
prev = current;
tempMax = current.getNext();
current = current.getNext();
}
else current = current.getNext();
}
prev.setNext(prev.getNext().getNext());
tempMax.setNext(toHere);
if (fromHere == null)
_head = tempMax;
else fromHere.setNext(tempMax);
fromHere = tempMax;
toHere = fromHere.getNext();
}
return this;
}

IntNoderather than movingIntNodearound.