container-doublylist
DoublyList implementation in JavaScript
To manage a list of elements. Best use case: elements are frequently removed from the list. Complexity in O(1) for addition and removal.
Note: Benchmarks seem to show that list iteration is as fast as array iteration on all major browsers.
To instantiate a new list:
var myList = ;
To add an element:
var myObjectReference = myList; // add on front by default// orvar myObjectReference = myList;// orvar myObjectReference = myList;
To remove an element:
myList; // O(1)// ormyList; // O(n)
To pop an element:
var myObject = myList; // pop from front by default// orvar myObject = myList;// orvar myObject = myList;
To insert an element before the given node:
var myOtherObjectReference = myList;
To insert an element after the given node:
var myOtherObjectReference = myList;
To move an element to the beginning:
myList;
To move an element to the end:
myList;
To iterate through the elements:
for var node = myListfirst; node !== null; node = nodenextnodeobject += 1;
To apply a treatment on all the elements:
myList;
To convert into an array:
var myArray = myList;