/**
 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param head ListNode类 
     * @return ListNode类
     */
    vector<int> getarray(ListNode* head){
        if(head==nullptr) return vector<int>{};
        vector<int> arr;
        while(head){
            arr.push_back(head->val);
            head=head->next;
        }
        return arr;
    }
    ListNode* sortList(ListNode* head) {
       ListNode* p=head;
       vector<int> arr=getarray(head);
       sort(arr.begin(),arr.end());
       int i=0;
       while(p){
        p->val=arr[i++];
        p=p->next;
       }
       return head;
    }
};