You are viewing a single comment's thread. Return to all comments →
Javascript:
function insertNodeAtPosition(llist, data, position) { if (position === 0) { return { data, next: llist } } let pointer = llist; const head = pointer; let counter = 1; while (pointer.next != null) { if (counter === position) { const node = { data, next: pointer.next } pointer.next = node; return head; } pointer = pointer.next; counter++; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Insert a node at a specific position in a linked list
You are viewing a single comment's thread. Return to all comments →
Javascript: