https://leetcode.com/problems/sort-list/description/
题目: 链表排序
思路: 我直接对值进行排序。。。
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* sortList(ListNode* head) {
ListNode* temp=head;
vector<int>v;
while(temp!=NULL)
{
v.push_back(temp->val);
temp=temp->next;
}
sort(v.begin(),v.end());
temp=head;int sum=0;
while(temp!=NULL)
{
temp->val=v[sum];
sum++;
temp=temp->next;
}
return head;
}
};