```
ListNode *insertionSortList(ListNode *head) {
if(head==NULL) return head;
ListNode *p = head;
int i = 1,j;
while(p->next!=NULL){
ListNode *q2 = head,*q1=NULL;
for(j=0;j<i&&q2!=NULL;j++){
if(p->next->val<q2->val){
ListNode *tmp = p->next;
p->next = p->next->next;
tmp->next = q2;
if(q1==NULL) head = tmp;
if(q1!=NULL) q1->next = tmp;
break;
}
q1 = q2;
q2 = q2->next;
}
p = p->next;
i++;
}
return head;
}
```