MCPcopy Create free account
hub / github.com/careercup/CtCI-6th-Edition-JavaScript / insertAt

Method insertAt

chapter02/util/LinkedListX.js:104–122  ·  view source on GitHub ↗
(index, value)

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 1

prependMethod · 0.95

Tested by

no test coverage detected