forked from knaxus/problem-solving-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (44 loc) · 934 Bytes
/
index.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const { LinkedList: SinglyLinkedLists } = require('../LinkedList');
class Queue extends SinglyLinkedLists {
constructor() {
super();
this.NotAllowed = 'Not Allowed';
}
enqueue(data) {
return this.addAtEnd(data);
}
dequeue() {
const node = this.removeFromBeginning();
return node ? node.data : node;
}
peek() {
const node = this.getFirst();
return node ? node.data : node;
}
length() {
return this.size;
}
destroy() {
this.delete();
}
/** Override and throw error for other LL methods */
addAtBeginning() {
throw new Error(this.NotAllowed);
}
addAt() {
throw new Error(this.NotAllowed);
}
removeFromEnd() {
throw new Error(this.NotAllowed);
}
getLast() {
throw new Error(this.NotAllowed);
}
getAt() {
throw new Error(this.NotAllowed);
}
removeAt() {
throw new Error(this.NotAllowed);
}
}
module.exports = Queue;