-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueArray.js
More file actions
56 lines (45 loc) · 873 Bytes
/
QueueArray.js
File metadata and controls
56 lines (45 loc) · 873 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
45
46
47
48
49
50
51
52
53
54
55
56
class Queue {
constructor(capacity) {
this.capacity = capacity;
this.length = 0;
this.list = [];
}
enqueue(item) {
if (this.length < this.capacity) {
this.list.push(item);
this.length++;
}
}
dequeue() {
if (this.length != 0) this.list.shift();
this.length--;
}
isEmpty(){
return this.length==0 ? true : false
}
isFull(){
return this.length==this.capacity
}
size(){
return this.length
}
print(){
// this.list.forEach((item)=>{
// console.log(item)
// })
console.log(this.list)
}
}
const queue = new Queue(5);
queue.enqueue(10)
queue.enqueue(20)
queue.enqueue(30)
queue.enqueue(40)
queue.print()
console.log("Size: "+queue.size())
console.log("Full: "+queue.isFull())
console.log("IsEmpty: "+queue.isEmpty())
queue.print()
queue.dequeue()
queue.dequeue()
queue.print()