In this Leetcode Insertion Sort List problem solution, we have given the head of a singly linked list, sort the list using insertion sort, and return the sorted list's head.

The steps of the insertion sort algorithm:

1. Insertion sort iterates, consuming one input element each repetition and growing a sorted output list.
2. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there.
3. It repeats until no input elements remain.

The following is a graphical example of the insertion sort algorithm. The partially sorted list (black) initially contains only the first element in the list. One element (red) is removed from the input data and inserted in place into the sorted list with each iteration.

## Problem solution in Python.

```class Solution:
def insertionSortList(self, head: ListNode) -> ListNode:
node=h
break
break
previous=node
node=node.next
return h
```

## Problem solution in Java.

```public class Solution {
ListNode pre = new ListNode(-11);
pre.next = sorted;
ListNode tempPre = pre;
while(pre.next != null && pre.next.val < head.val) {
pre = pre.next;
}
ListNode temp = pre.next;
pre.next.next = temp;
pre = tempPre;
} else {
sorted = sorted.next;
}
}
return pre.next;
}

}
```

## Problem solution in C++.

```class Solution {
public:
ListNode dummy(0);

ListNode *it = &dummy;
while (it->next && it->next->val < head->val) {
it = it->next;
}
}

return dummy.next;
}
};
```

## Problem solution in C.

```struct ListNode* insertionSortList(struct ListNode* head) {
struct ListNode *temp = NULL;
struct ListNode *cur = NULL;
struct ListNode *p = NULL;
{
{
}
}
while (p)
{
{
temp->next = p->next;
p = p->next;
cur = p;
}
else
{
if (temp->val < cur->val)
{
temp = cur;
p = p->next;
cur = p;
}
else
{
while (q->next != temp && q->val < cur->val && q->next->val < cur->val)
{
q = q->next;
}
temp->next = p->next;
p = p->next;
cur->next = q->next;
q->next = cur;
cur = p;
}
}
}