我正试图为链表类进行插入排序以升序排序。我不太确定我需要做什么。我找不到返回列表开头的方法。
public static void LLInsertionSort (LinkedList LL){
IntNode currentNode = head;
IntNode tail = null;
while(currentNode != null&& tail != head ){
while (currentNode.getData() > currentNode.getNext().getData()){
int temp = currentNode.getData();
currentNode.setData(currentNode.getNext().getData());
currentNode.getNext().setData(temp);
每次都需要从列表中的第一个节点开始。
public static IntList LLInsertionSort(Node head)
{
IntNode current = head;
IntNode tail = null;
while(current != null&& tail != head )
{
IntNode next = current;
for( ; next.next != tail; next = next.next)
{
if(next.value <= next.next.value)
{
int temp = next.value;
next.value = next.next.value;
next.next.value = temp;
}
}
tail = next;
current = head;
}
return this;
}