-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.js
More file actions
44 lines (35 loc) · 664 Bytes
/
queue.js
File metadata and controls
44 lines (35 loc) · 664 Bytes
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
class Queue {
#array
constructor() {
this.#array = [];
}
push(data) {
this.#array.push(data);
}
pop() {
if (this.isEmpty()) {
return "Queue Underflow Error";
}
return this.#array.shift();
}
peek() {
if (this.isEmpty()) {
return "Queue is Empty";
}
return this.#array[0];
}
length() {
return this.#array.length;
}
clear() {
this.#array = [];
}
isEmpty() {
return this.length() === 0;
}
display() {
this.#array.map((i) => {
console.log(i);
});
}
}