-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.js
55 lines (44 loc) · 890 Bytes
/
queue.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
/**
* @classdesc Queue ini untuk melakukan
* pop: pada brick yang sudah tidak terlihat (dibawah)
* push: menambahkan diatasnya
* sesuai FIFO
*/
const Brick = require('./brick');
class Queue {
constructor() {
/**
* @type {Array.<Brick>} Items - Array of Brick
*/
this.items = [];
}
pop() {
this.items.shift();
}
/**
* @param {Brick} element
*/
push(element) {
this.items.push(element);
}
front() {
return this.items[0];
}
back() {
return this.items[this.size() - 1];
}
get(index) {
return this.items[index];
}
set(item) {
var index = this.size() - 1;
this.items[index] = item;
}
size() {
return this.items.length;
}
clear() {
return this.items.length = 0;
}
}
module.exports = Queue;