/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* insertionSortList(struct ListNode* head) {
struct ListNode *node=(struct ListNode*)malloc(sizeof(struct ListNode));
struct ListNode* cur;
struct ListNode* tmp;
struct ListNode* pre;
struct ListNode* end;
node->next=head;
if(head!=NULL&&head->next!=NULL){
cur=head->next;
end=head;
while(cur!=NULL){
pre=node;
if (cur->val>=end->val){
end=cur;
}
else{
while(cur->val>=pre->next->val){
pre=pre->next;
}
tmp=pre->next;
end->next=cur->next;
pre->next=cur;
cur->next=tmp;
}
cur=end->next;
}
}
return node->next;
}
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* insertionSortList(struct ListNode* head) {
struct ListNode *node=(struct ListNode*)malloc(sizeof(struct ListNode));
struct ListNode* cur;
struct ListNode* tmp;
struct ListNode* pre;
struct ListNode* end;
node->next=head;
if(head!=NULL&&head->next!=NULL){
cur=head->next;
end=head;
while(cur!=NULL){
pre=node;
if (cur->val>=end->val){
end=cur;
}
else{
while(cur->val>=pre->next->val){
pre=pre->next;
}
tmp=pre->next;
end->next=cur->next;
pre->next=cur;
cur->next=tmp;
}
cur=end->next;
}
}
return node->next;
}