Code:
public static IntNode listSort(IntNode head)
{
IntNode cursor;
int largest;
IntNode copyHead=null;
IntNode target=null;
while(head!=null)
{
largest = Integer.MIN_VALUE;
for(cursor=head.link;cursor!=null;cursor=cursor.link)
{
if(cursor.data > largest)
{
target=cursor;
largest=cursor.data;
}
}
copyHead = new IntNode(target.data, copyHead);
target.setData(head.data);
head=head.link;
}
return copyHead;
}
this is the closest I have gotten so far. It works about half of the time, and the other half it is off by 1. I tested many different sets of numbers, it seems random when it does or does not work.