算法

  • child::

    遍历单向链表

    拿下一个节点来操作

    • 因为单向链表的大多数操作都是需要前一个节点
    • 所以遍历的时候,进行操作判断的通常是下一个节点

    示例

     if(cur.next?.val<x){
        let toInsert = splice(cur)//取出cur下一个node
        insert(left,toInsert)//left后面插入一个节点
    } else {
        cur = cur.next
    }
    指向原始笔记的链接
  • child::

    单向链表取出节点

    示例

    function splice(nodeBefore){
            let n = nodeBefore.next
            nodeBefore.next = nodeBefore.next.next
            return n
    }
    指向原始笔记的链接
  • child::

    单向链表插入节点

    示例

    function insert(nodeBefore,target){
        target.next = nodeBefore.next
        nodeBefore.next = target
    }
    指向原始笔记的链接