/*
* function ListNode(x){
* this.val = x;
* this.next = null;
* }
*/
/**
*
* 类似一个插入排序的写法,比较耗时
*/
function sortInList( head ) {
let node = {val:-Infinity,next:null};
while(head){
let temp = head.next;
let cur = node;
let flag=true;
let prev;
while(cur){
if(cur.val<=head.val){
prev = cur;
cur=cur.next;
}
else{
head.next=cur;
prev.next=head;
flag=false;
break;
}
}
if(flag){
head.next=null;
prev.next=head;
}
head=temp;
}
return node.next;
}
module.exports = {
sortInList : sortInList
}; 


京公网安备 11010502036488号