Function LinkedList() {function Node(element) {this.node = element; this.next = null; } // this.head = null; this.length = 0; / / append () to the chain table tail added a LinkedList. Prototype. Append = function (element) {let node = new node (element); if (this.length === 0) { this.head = node; } else { let current = this.head; while (current.next) { current = current.next; } current.next = node; } this.length += 1; } / / insert (position, element) into a LinkedList. Prototype. Insert = function (position, element) { if (position < 0 || position > this.length) return false; let node = new Node(element); if (position == 0) { node.next = this.head; this.head = node; } else { let current = this.head, index = 0, prev; while (index++ < position) { prev = current current = current.next } prev.next = node; node.next = current; } this.length += 1; } / / removeAt () according to the subscript removed from the list of LinkedList. The prototype. The removeAt = function (position) {if (position < 0 | | position > this.length) return false; if (position == 0) { this.head = this.head.next; } else { let current = this.head, index = 0, prev; while (index++ < position) { prev = current; current = current.next; } prev.next = current.next; } this.length -= 1; } / / remove according to the element from the list to remove LinkedList. Prototype. Remove = function (element) {let index = this. IndexOf (element); Enclosing removeAt (index)} / / get access to LinkedList. Prototype. Get = function (position) {if (position < 0 | | position > this.length) return null; let current = this.head, index = 0; while (index++ < position) { current = current.next; } return current.node; } / / indexOf return a LinkedList element index. The prototype. The indexOf = function (element) {let current = this. The head, the index = 0; while (current) { if (current.node == element) { return index; } index++; current = current.next; } return -1; LinkedList} / / update () modify elements. The prototype. Update = function (position, element) { if (position < 0 || position > this.length) return null; let current = this.head, index = 0; while (index++ < position) { current = current.next } current.node = element; } / / isEmpty () is null chain LinkedList. Prototype. IsEmpty = function () {return! Boolean(this.length); } / / the size () chain table length LinkedList. Prototype. Size = function () {return this. Length; } / / the toString () turn list of string LinkedList. Prototype. ToString = function () {let current = this. The head, the result = ', comma. while (current) { comma = current.next ? ',' : '' result += current.node + comma; current = current.next; } return result; } } let linked = new LinkedList();Copy the code