(index, value)
| 89 | } |
| 90 | |
| 91 | insertAt(index, value) { |
| 92 | if (index == 0) return this.prepend(value); |
| 93 | let cur = this.head; |
| 94 | let i = 0; |
| 95 | |
| 96 | while (cur != null) { |
| 97 | if (i == index - 1) { |
| 98 | let node = new Node(value); |
| 99 | node.next = cur.next; |
| 100 | cur.next = node; |
| 101 | return true; |
| 102 | } |
| 103 | else { |
| 104 | i++; |
| 105 | cur = cur.next; |
| 106 | } |
| 107 | } |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | tail() { |
| 112 | return this.tail; |