思路

代码实现
package qiuzhaoprepare;
class ListNode{
int val;
ListNode next;
ListNode(int x){
val = x;
}
}
public class SingleListQuickSort {
public ListNode partition(ListNode begin, ListNode end) {
if(begin == end)
return begin;
int val = begin.val;
ListNode p1 = begin;
ListNode p2 = begin.next;
while(p2 != end) {
if(p2.val < val) {
p1 = p1.next;
int temp = p1.val;
p1.val = p2.val;
p2.val = temp;
}
p2 = p2.next;
}
int temp = begin.val;
begin.val = p1.val;
p1.val = temp;
return p1;
}
public void quickSort(ListNode head, ListNode end) {
if(head != end){
ListNode node = partition(head, end);
quickSort(head, node);
quickSort(node.next, end);
}
}
public void printSingleList(ListNode head) {
while(head != null) {
System.out.println(head.val);
head = head.next;
}
}
public static void main(String[] args) {
ListNode head = new ListNode(4);
ListNode ListNode1 = new ListNode(2);
ListNode ListNode2 = new ListNode(5);
ListNode ListNode3 = new ListNode(3);
ListNode ListNode4 = new ListNode(7);
ListNode ListNode5 = new ListNode(9);
ListNode ListNode6 = new ListNode(0);
ListNode ListNode7 = new ListNode(1);
head.next = ListNode1;
ListNode1.next = ListNode2;
ListNode2.next = ListNode3;
ListNode3.next = ListNode4;
ListNode4.next = ListNode5;
ListNode5.next = ListNode6;
ListNode6.next = ListNode7;
SingleListQuickSort singleListQuickSort = new SingleListQuickSort();
singleListQuickSort.quickSort(head, null);
singleListQuickSort.printSingleList(head);
}
}