(index, value)
| 102 | } |
| 103 | |
| 104 | insertAt(index, value) { |
| 105 | if (index == 0) return this.prepend(value); |
| 106 | let cur = this.head; |
| 107 | let i = 0; |
| 108 | |
| 109 | while (cur != null) { |
| 110 | if (i == index - 1) { |
| 111 | let node = new Node(value); |
| 112 | node.next = cur.next; |
| 113 | cur.next = node; |
| 114 | return true; |
| 115 | } |
| 116 | else { |
| 117 | i++; |
| 118 | cur = cur.next; |
| 119 | } |
| 120 | } |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | tail() { |
| 125 | return this.tail; |