array-deque
v1.0.1
Published
Array-backed implementation of a deque. Supports O(1) random access, and amortized O(1) insertion and removal at the front and back of the deque
Downloads
7
Readme
ArrayDeque
Array-backed implementation of a deque. Supports O(1) random access, and amortized O(1) insertion and removal at the front and back of the deque
Kind: global class
- ArrayDeque
- new ArrayDeque(initSize, x)
- .push_front(x)
- .set(i, x) ⇒ *
- .push_back(x)
- .pop_front() ⇒ *
- .pop_back() ⇒ *
- .toArray() ⇒ Array.<any>
new ArrayDeque(initSize, x)
Creates a new deque with size = initSize, and initializes elements to x. If no initSize is provided, returns a deque with size = 0
| Param | | --- | | initSize | | x |
arrayDeque.push_front(x)
Inserts x at the front / beginning of the deque
Kind: instance method of ArrayDeque
| Param | | --- | | x |
arrayDeque.set(i, x) ⇒ *
Sets the ith element to x, returns the previous ith element. Returns undefined if index is out of range ( i < 0 || i >= deque.size)
Kind: instance method of ArrayDeque
Returns: * - Previous element at i
| Param | Description | | --- | --- | | i | Index of the element to set | | x | The value that should be set |
arrayDeque.push_back(x)
Inserts x at the back / end of the deque
Kind: instance method of ArrayDeque
| Param | | --- | | x |
arrayDeque.pop_front() ⇒ *
Removes and returns the first element in the deque or undefined if there aren't any elements in the deque
Kind: instance method of ArrayDeque
Returns: * - First element in the deque
arrayDeque.pop_back() ⇒ *
Removes and returns the last element in the deque or undefined if there aren't any elements in the deque
Kind: instance method of ArrayDeque
Returns: * - Last element in the deque
arrayDeque.toArray() ⇒ Array.<any>
Returns an array containing the elements of the deque
Kind: instance method of ArrayDeque