Creates a singly-linked list, optionally filled with the elements generated by the given iterable.
const l = new DoubleinkedList();
You can also construct a linked list from any iterable, like so:
const l = new DoubleLinkedList([1, 2, 3])
Optional
iterable: Iterable<T, any, any>Count the amount of elements in the collection.
⚠️ In most cases, this should be an O(1)
operation. However, there are
cases where this can be an O(n)
operation. Therefore, it is recommended
to always cache the result in a local variable.
Returns an object which is able to sift through the values in this collection.
The order by which the elements are traversed depends on the kind of collection. For unordered collections, the iteration order is unspecified and may even differ between two iterations on the same collection.
This method's time complexity is in O(1)
.
Append an item at the end of the collection. The element will be given the highest order.
Return a cursor that is placed at the index given by position
in the
sequence.
Copies all elements in the collection to a new one of the same kind.
Insert an element after the element at the given position. The position is deduced from the iterator that is given to the method.
Insert an element before the element at the given position. The position is deduced from the iterator that is goven to the method.
Prepend an item to the beginning of the collection. The element will be given the lowest order.
Converts the entire collection to a range.
Static
emptyStatic
from
A FIFO queue, where the first element pushed into the collection is also the first to be popped out of it.
Pushing and popping an element are both in
O(1)
.The following table summarises the time complexity of the most commonly used properties.
See