# 单链表排序

import java.util.ArrayList;
import java.util.List;

class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }
}

public class Solution {
//快速排序
return null;
}

pivot.next = null;
return pivot;
}

ListNode pivotTail = pivot;

leftTail = leftTail.next;
pivotTail = pivotTail.next;
}else {
rightTail = rightTail.next;
}
}

leftTail.next = null;
pivotTail.next = null;
rightTail.next = null;

}else {
while (connectLeftRight.next != null){
connectLeftRight = connectLeftRight.next;
}
connectLeftRight.next = pivot;
}

}

//归并排序
ListNode result = new ListNode(0);
}else {
}
result = result.next;
}

}else {
}

}

}

while (fastPointer != null && fastPointer.next != null){
prePointer = slowPointer;
slowPointer = slowPointer.next;
fastPointer = fastPointer.next.next;
}

prePointer.next = null;

}

//转换为数组处理
}

List<ListNode> arrayList = new ArrayList<>();

}

ListNode result = new ListNode(0);
arrayList.sort((node1,node2)->Integer.compare(node1.val, node2.val));
for(ListNode node : arrayList){
result.next = node;
result = result.next;
}
result.next = null;
}

public static void main(String[] args){
ListNode one = new ListNode(3);
ListNode two = new ListNode(1);
ListNode three = new ListNode(2);
one.next = two;
two.next = three;
three.next = null;
while (re != null){
System.out.print(re.val + " ");
re = re.next;
}
}
}


09-30 1707

08-08 2045

11-18 1947

07-27 1394

03-27 1360

04-13 1.3万

11-26 2488

#### 单链表实现从小到大排序

2010年05月24日 2KB 下载

12-02 1428

07-08 1.3万