Brief intro: code not optimized, debugged in VC for 2 hours...ok, this is lame... But luckily one time accepted.

```
ListNode *insertionSortList(ListNode *head) {
if (head == nullptr || head->next==nullptr)
{
return head;
}
ListNode* t = head->next;
ListNode* pre_t = head;
for (; t!=nullptr;)
{
ListNode* a = head;
int tval = t->val;
int aval = a->val;
ListNode* pre_a = t;// in case t is the smallest.
while ((a != t) && tval > aval){
pre_a = a;
a = a->next;
aval = a->val;
}
ListNode* u = t->next;
if (a != t)
{
//in case we had to move element,
//pre_t will not be changed for the next loop
//because t will be u in that loop.
pre_t->next = u;
t->next = a;
if (pre_a != t)
{
pre_a->next = t;
}
else
{// make the new smallest as head.
head = t;
}
}
else
{ //in case we don't need to insert,
//we had to prepare for the next loop
//pre_t will be t since t will be u.
pre_t = t;
}
t = u;
}
return head;
}
```