forked from yangshun/lago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeque.js
37 lines (32 loc) · 821 Bytes
/
Deque.js
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 extends DoublyLinkedList {
/**
* Adds an element to the back of the Deque.
* @param {*} element The element to be queued to the back of the Deque.
*/
enqueue(element) {
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) {
this.unshift(element);
}
/**
* Removes the element at the front of the Deque.
* @return {*} The element at the front of the Deque.
*/
dequeue() {
return this.shift();
}
/**
* Removes the element at the back of the Deque.
* @return {*} The element at the back of the Deque.
*/
dequeueBack() {
return this.pop();
}
}
export default Deque;