class Solution {
public:
ListNode* insertionSortList(ListNode* head) {
if(!head||!head->next)return head;
ListNode* cur=head->next;
ListNode* dummy =new ListNode();
dummy->next=head;
head->next=nullptr;
while(cur){
ListNode *p=dummy->next;
ListNode *pre=dummy;
while(p&&cur->val>p->val){
pre=p;
p=p->next;
}
ListNode*temp=cur->next;
cur->next=p;
pre->next=cur;
cur=temp;
}
return dummy->next;
}
};