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