<?php
class ListNode {
public $val = 0;
public $next = null;
function __construct($val) { $this->val = $val; }
}
function sortInList( $head )
{
    $cur = new ListNode(-1);
    $new = $cur;
    $array = [];
    while($head){
        $array[] = $head->val;
        $head = $head->next;
    }
    asort($array);
    foreach($array as $val){
        $new->next = new ListNode($val);
        $new = $new->next;
    }
    return $cur->next;
    // write code here
}
$ha = new ListNode(8);
$pre = $ha;
for($i = 1;$i<19;$i++){
    $tmp = new ListNode($i);
    $pre->next = $tmp;
    $pre = $tmp;
}
$c = sortInList($ha);
while($c){
    var_dump($c->val);
    $c = $c->next;
}
  
                
        
        
    
  
 
 |