
请问下面的问题,有没有人会呢
/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
class Solution {
public:
/**
*
* @param head ListNode类
* @return ListNode类
*/
ListNode* insertionSortList(ListNode* head) {
if(head == NULL || head->next == NULL)
return head;
ListNode* i=head->next;
ListNode dummy(0);
dummy.next = head;
dummy.next->next=NULL;
ListNode* j=&dummy;
ListNode* temp;
while(i!=NULL){
j=&dummy;
while( j->next!=NULL && j->next->val < i->val) {j=j->next;}
temp=i;
i=i->next;
temp->next = j->next;
j->next = temp;
}
return dummy.next;
}
};