-
Notifications
You must be signed in to change notification settings - Fork 314
/
Deque.ts
37 lines (32 loc) · 875 Bytes
/
Deque.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import DoublyLinkedList from './DoublyLinkedList';
class Deque<T> extends DoublyLinkedList<T> {
/**
* Adds an element to the back of the Deque.
* @param {*} element The element to be queued to the back of the Deque.
*/
enqueue(element: T): void {
this.push(element);
}
/**
* Adds an element to the front of the Deque.
* @param {*} element The element to be queued to the front of the Deque.
*/
enqueueFront(element: T): void {
this.unshift(element);
}
/**
* Removes the element at the front of the Deque.
* @return {*} The element at the front of the Deque.
*/
dequeue(): T | undefined {
return this.shift();
}
/**
* Removes the element at the back of the Deque.
* @return {*} The element at the back of the Deque.
*/
dequeueBack(): T | undefined {
return this.pop();
}
}
export default Deque;