(排序)链表的插入排序
/* * function ListNode(x){ * this.val = x; * this.next = null; * } */ /** * * @param head ListNode类 * @return ListNode类 */ function insertionSortList( head ) { // write code here if(head==null || head.next==null) { return head; } var preHead = new ListNode(-1); var curr = head; while(curr){ var pre = preHead; var next = curr.next; while(pre.next && pre.next.val < curr.val){ pre = pre.next } curr.next = pre.next; pre.next = curr; curr = next; } return preHead.next; } module.exports = { insertionSortList : insertionSortList };
其他算法 文章被收录于专栏
其他算法