-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeque.js
More file actions
43 lines (43 loc) · 1.08 KB
/
deque.js
File metadata and controls
43 lines (43 loc) · 1.08 KB
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
38
39
40
41
42
43
class deque{
constructor(){
this.items = [];
}
addFront(element){
this.items.push(element);
}
addBack(element){
this.items.unshift(element);
}
removeFront(){
return this.items.pop();
}
removeBack(){
return this.items.shift();
}
peekFront(){
return this.items[this.items.length-1];
}
peekBack(){
return this.items[0];
}
}
module.exports={
structure:deque,
description:"Double Ended Queue",
methods:{
addFront:"Adds an element to the front of the queue",
addBack:"Adds an element to the back of the queue",
removeFront:"Removes an element from the front of the queue",
removeBack:"Removes an element from the back of the queue",
peekFront:"Returns the element at the front of the queue",
peekBack:"Returns the element at the back of the queue"
},
complexity:{
addFront:"O(1)",
addBack:"O(1)",
removeFront:"O(1)",
removeBack:"O(1)",
peekFront:"O(1)",
peekBack:"O(1)"
}
};