Given 1->3->2->0->null, return 0->1->2->3->null
/**
- Definition of ListNode
- class ListNode {
- public:
- int val;
- ListNode *next;
- ListNode(int val) {
- this->val = val;
- this->next = NULL;
- }
- } */
class Solution {
public:
/*
* @param head: The first node of linked list.
* @return: The head of linked list.
/
ListNode * insertionSortList(ListNode * head) {
// write your code here
ListNode temp1=head;
if(temp1->next==NULL)
return head;
vector<int> vec;
while(temp1!=NULL)
{
vec.push_back(temp1->val);
temp1=temp1->next;
}
sort(vec.begin(),vec.end());
ListNode* returnhead;
ListNode* temp2=returnhead;
for (auto c:vec)
{
temp2 = new ListNode(c);
temp2=temp2->next;
}
return returnhead;
}
};
请问哪里出错了?