void InsertSort(struct ListNode* L){ struct ListNode *p = L->next,*pre=NULL; struct ListNode *r = p->next; p->next = NULL; p = r; while(p!=NULL){ r = p->next; pre = L; while(pre->next!=NULL && pre->next->val<p->val){ pre = pre->next; } p->next = pre->next; pre->next = p; p = r; } } struct ListNode* insertionSortList(struct ListNode* head) { if(head==NULL) return head; struct ListNode* L = (struct ListNode*)malloc(sizeof(struct ListNode)); //借一个头节点 L->next = head; InsertSort(L); head = L->next; free(L); //还一个头结点 return head; }