Readonly
lengthspecify the maximum length of the queue. pushing more items than the length will remove the items from the opposite side, so as to maintain the size.
iterate over the items in this deque, starting from the rear-most item, and ending at the front-most item.
inserts one or more items to the rear of the deque.
if the deque is full, it will remove the front item before adding a new item.
inserts one or more items to the front of the deque.
if the deque is full, it will remove the rear item before adding a new item.
get the item at the back of the deque without removing/popping it.
get the item at the front of the deque without removing/popping it.
removes/pops the item at the back of the deque and returns it.
removes/pops the item at the front of the deque and returns it.
rotates the deque steps
number of positions to the right.
if steps
is negative, then it will rotate in the left direction.
when the deque is not empty, rotating with step = 1
is equivalent to this.pushBack(this.popFront())
reverses the order of the items in the deque.
returns the item at the specified index, relative to the rear of the deque.
if the capacity (element count) of this deque is not full,
then you may receive undefined
when you provide an index where an empty element exists.
in other words, this method is not aware of the number of elements currently stored in the deque.
to obtain an element that is always within the current partial capacity limit, use the seek method instead.
The index of the item to retrieve, relative to the rear-most element.
The item at the specified index, or undefined
if the index is out of range with respect to the current count number of items.
returns the item at the specified index, relative to the rear of the deque, ensuring that the index circulates back if it goes off the current item count amount.
if the capacity (element count) of this deque is not full,
then you may receive undefined
when you provide an index where an empty element exists.
in other words, this method is not aware of the number of elements currently stored in the deque.
to obtain an element that is always within the current partial capacity limit, use the seek method instead.
The index of the item to retrieve, relative to the rear-most element.
The item at the specified index (within the element count amount of this deque), or undefined
if there are absolutely no items in the deque.
replaces the item at the specified index with a new item, always ensuring the index is bound to the current element count amount (as opposed the the full deque length), so that unoccupied element slots are not replaced. i.e. only existing items can be replaced.
inserts additional items at the specified seek-index, shifting all items ahead of it to the front. if the deque is full, it removes the front item before adding the new additional items.
TODO: current implementation is incomplete, because it involves too many index computations, and I'm too lazy for that.
plus, president biden is going to drop the "ball" in times square today on new year's eve.
obviously I wouldn't want to miss this historic moment. /s
in place of a lackluster "ball drop", we got a much more exciting thunder show from the Almighty Himself!
a resizable double-ended circular queue, similar to python's
collection.deque
.Example