Queue.js
708 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
/*
* @Descripttion:
* @version: 1.0.0
* @Author: limin
* @Date: 2024-07-01 09:41:43
* @LastEditors: limin
* @LastEditTime: 2025-01-06 09:36:58
* @FilePath: \gl_tape\utils\Queue.js
*/
class Queue {
_items = [];
constructor(items = []) {
this._items = items;
}
enqueue(item) {
this._items.push(item);
}
dequeue() {
return this._items.shift();
}
get head() {
return this._items[0];
}
get tail() {
return this._items[this._items.length - 1];
}
get items() {
return this._items;
}
get isEmpty() {
return !this._items.length;
}
get size() {
return this._items.length;
}
clear() {
this._items = [];
}
}
export default Queue;