text: /**
   * 实现非连续内存存储 - 链表
   */
  class Node {
    constructor(element, next) {
      this.element = element
      this.next = next
    }
  }
  
  class LinkedList {
    constructor() {
      this.head = null
      this.length = 0
    }
  
    _getNode(index) {
      let currrentNode = this.head
      for (let i = 0; i < index; i++) {
        currrentNode = currrentNode.next
      }
  
      return currrentNode
    }
  
    push(element) {
      if (this.length === 0) {
        this.head = new Node(element, null)
      } else {
        let lastNode = this._getNode(this.length - 1)
        lastNode.next = new Node(element, null)
      }
  
      this.length++
    }
  
    insert(index, element) {
      if (index < 0 || index > this.length) {
        throw new Error('超出插入范围')
      }
  
      if (index === 0) {
        this.head = new Node(element, this.head)
      } else {
        let preNode = this._getNode(index - 1)
        preNode.next = new Node(element, preNode.next)
      }
  
      this.length++
    }
  
    removeByElement(element) {
      let currentNode = this.head
      let prevNode = this.head
  
      for (let i = 0; i < this.length; i++) {
        if (currentNode.element === element) {
          prevNode.next = currentNode.next
          this.length--
          return currentNode
        }
        prevNode = currentNode
        currentNode = currentNode.next
      }
    }
  
    removeByIndex(index) {
      if (index < 0 || index >= this.length) {
        throw new Error('超出删除范围')
      }
  
      let rmNode = null
  
      if (index === 0) {
        rmNode = this.head
        this.head = rmNode.next
      } else {
        let prevNode = this._getNode(index - 1)
        rmNode = prevNode.next
        prevNode.next = rmNode.next
      }
  
      this.length--
  
      return rmNode
    }
  
    clear() {
      this.head = null
      this.length = 0
    }
  
    getNode(index) {
      return this._getNode(index)
    }
  
    toString() {
      let currentNode = this.head
      for (let index = 0; index < this.length; index++) {
        console.log(currentNode.element)
        currentNode = currentNode.next
      }
    }
  }
  
  exports.LinkedList = LinkedList
  
  // let link = new LinkedList()
  
  // link.push('node1')
  // link.push('node2')
  // link.push('node3')
  // link.insert(1, 'node4')
  // link.insert(2, 'node5')
  // let x = link.removeByElement('node4')
  // let y = link.removeByIndex(1)
  
  // console.log(x, y)
  // console.log(link.getNode(1))
  
  // link.toString()
  
  let link = new LinkedList()
  
  link.insert(0, 'node4')
  link.insert(0, 'node5')
  link.insert(1, 'node6')
  
  link.toString()
  
  