链表实现
def insertionSortList(head):
dummyhead = Node(0)
dummyhead.next=head
lastsorted = head
cur = head.next
while cur:
if cur.val>= lastsorted.val:
lastsorted=lastsorted.next
else:
pre =dummyhead
while pre.next.val<= cur.val:# 找到大于当前值的结点
pre=pre.next # pre 是插入cur 的前一个位置
lastsorted.next=cur.next # 继承cur 后面的结点
cur.next = pre.next # 继承pre后面的结点
pre.next =cur
cur=lastsorted.next # cur 是 原来cur.next
return dummyhead