<commit_before># Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def insert(self, head, node):
        if head.val > node.val:
            node.next = head
            head = node
            return
        else:
            last = head
            current = head.next

        while True:
            if current is None:
                last.next = node
                node.next = None
                return
            elif current.val <= node.val:
                last = current
                current = current.next
                continue
            else:
                last.next = node
                node.next = current
                return

    # @param head, a ListNode
    # @return a ListNode
    def insertionSortList(self, head):
        if not head or not head.next:
            return head

        last = head
        current = head.next
        while current:
            last.next = None
            next_node = current.next
            self.insert(head, current)
            last = current
            current = next_node
        return head
        <commit_msg>dummy variable and diagram wiring between current, previous, tmp<commit_after># Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

# 0     -> 1   -> 3 -> 4        -> 2   -> None
# dummy    pre         curr        tmp
#          1   -> 2 -> 3        -> 4   -> None
#          pre    tmp  pre.next    curr
class Solution:
    # @param head, a ListNode
    # @return a ListNode
    def insertionSortList(self, head):
        if not head:
            return head

        dummy = ListNode(0) # add a dummy node to head
        dummy.next = head

        current = head
        while current.next:
            if current.next.val > current.val: # continue iteration if ascending
                current = current.next
            else:
                pre = dummy
                while pre.next.val < current.next.val: # move current.next to the right place
                    pre = pre.next
                tmp = current.next
                current.next = tmp.next
                tmp.next = pre.next
                pre.next = tmp

        return dummy.next
{'fraction_non_alphanumeric': 0.07497857754927163, 'fraction_numerical': 0.004284490145672665, 'mean_word_length': 1.2049102927289896, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '807418', 'n_tokens_mistral': 620, 'n_tokens_neox': 584, 'n_words': 199}