doubly-linked-list
doubly-linked-list copied to clipboard
`remove(node)`, `addPrevious(node, nodeData)`, `addNext(node, nodeData)` are missing
Hi,
I was considering to use this library, but it seems to miss three very important methods on its API, namely a way to insert or remove a node not by providing the index, but by providing the node itself.
This should be constant time for a doubly linked list and is a very important feature of this datastructure when used to optimize runtime complexity in algorithms.
I also needed removeGivenNode
and restoreGivenNode
functions. I created a new class locally and extended this LinkedList with the following implementation:
removeGivenNode: function (node) {
node.prev.next = node.next;
node.next.prev = node.prev;
},
restoreGivenNode: function (node) {
node.prev.next = node;
node.next.prev = node;
},
This removes given node in constant time. If you hold onto the node, you can also put it back into the list.
Hope this helps!