/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
int quick_sort(ListNode* begin, ListNode* end, int temp){
if(begin == end){
return 0;
}
int key = begin->val;
ListNode* left = begin;
ListNode* right = left->next;
while(right !=end){
if(right->val < key){
left = left->next;
temp = left->val;
left->val = right->val;
right->val = temp;
}
right = right->next;
}
temp = left->val;
left->val = begin->val;
begin->val = temp;
quick_sort(begin, left, 0);
quick_sort(left->next, end, 0);
return 0;
};
ListNode* sortList(ListNode* head) {
quick_sort(head, nullptr, 0);
return head;
}
};