2016-09-19 2 views
-2

링크 된 목록 클래스에 대한 삽입 정렬을 오름차순으로 정렬하려고합니다. 내가 뭘해야하는지 잘 모르겠다. 나는 목록의 시작으로 돌아갈 길을 찾을 수 없다.삽입 정렬 단일 링크 된 목록 Java

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); 
+1

* 한숨이 실제로 JavaScript와 관련이있을 것이라고 확신하지만 ... 우리는 오늘 우리가 말한 것과 똑같은 말을해야한다고 생각합니다. – vlaz

+0

코드가 불완전합니다. 또한, 변수가'head'이지만, 어디에서 왔는지는 불분명합니다. 왜 그것을 사용할 수 없습니까? 또한 왜 노드를 다시 구성하지 않고 노드'데이터 '를 교체하고 있습니까? – Taylor

답변

0

당신은 목록에 첫 번째 노드에서 각각의 시간을 시작해야합니다.

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; 
}