/*
 * public class ListNode {
 *   int val;
 *   ListNode next = null;
 * }
 */

public class Solution {
    /**
     * 
     * @param head ListNode类 the head node
     * @return ListNode类
     */
    public ListNode sortInList (ListNode head) {
        // write code here
        if(head == null || head.next == null){
            return head;
        }
        List<Integer> temp = new ArrayList<>();
        
       ListNode currentNode = head;
        while(currentNode != null){
            temp.add(currentNode.val);
            currentNode = currentNode.next;
        }
        int[] data = new int[temp.size()];
        for(int i = 0;i<temp.size();i++){
            data[i] = temp.get(i);
        }
        
        Arrays.sort(data);
        
        ListNode newHead = new ListNode(-1);
        ListNode tempNode = newHead;
        for(int i : data){
            ListNode  cur = new ListNode(i);
            tempNode.next = cur;
            tempNode = cur;
        }
        return newHead.next;
    }
}