Leetcode 148 Sort List
//Leetcode 148 Sort List
struct ListNode{
int val;
ListNode* next;
ListNode(int x):val(x),next(NULL) {}
};
class Solution {
public:
ListNode* sortList(ListNode* head) {
ListNode* list = head;
while(list){
bubbleList(list);
list = list->next;
}
return head;
}
void bubbleList(ListNode* head){
ListNode* p1 = head->next;
while(p1){
if(p1->val < head->val){
int temp = p1->val;
p1->val = head->val;
head->val = temp;
}
p1 = p1->next;
}
}
};