@@ -5,84 +5,84 @@ export interface QueueNode<T> {
5
5
}
6
6
7
7
export default class Queue < T > {
8
- #length = 0 ;
8
+ private _length = 0 ;
9
9
10
10
get length ( ) {
11
- return this . #length ;
11
+ return this . _length ;
12
12
}
13
13
14
- #head : QueueNode < T > | null = null ;
14
+ private _head : QueueNode < T > | null = null ;
15
15
16
16
get head ( ) {
17
- return this . #head ;
17
+ return this . _head ;
18
18
}
19
19
20
- #tail : QueueNode < T > | null = null ;
20
+ _tail : QueueNode < T > | null = null ;
21
21
22
22
get tail ( ) {
23
- return this . #tail ;
23
+ return this . _tail ;
24
24
}
25
25
26
26
push ( value : T ) {
27
- ++ this . #length ;
27
+ ++ this . _length ;
28
28
29
- if ( ! this . #tail ) {
30
- return this . #tail = this . #head = {
31
- previous : this . #head ,
29
+ if ( ! this . _tail ) {
30
+ return this . _tail = this . _head = {
31
+ previous : this . _head ,
32
32
next : null ,
33
33
value
34
34
} ;
35
35
}
36
36
37
- return this . #tail = this . #tail . next = {
38
- previous : this . #tail ,
37
+ return this . _tail = this . _tail . next = {
38
+ previous : this . _tail ,
39
39
next : null ,
40
40
value
41
41
} ;
42
42
}
43
43
44
44
unshift ( value : T ) {
45
- ++ this . #length ;
45
+ ++ this . _length ;
46
46
47
- if ( ! this . #head ) {
48
- return this . #head = this . #tail = {
47
+ if ( ! this . _head ) {
48
+ return this . _head = this . _tail = {
49
49
previous : null ,
50
50
next : null ,
51
51
value
52
52
} ;
53
53
}
54
54
55
- return this . #head = this . #head . previous = {
55
+ return this . _head = this . _head . previous = {
56
56
previous : null ,
57
- next : this . #head ,
57
+ next : this . _head ,
58
58
value
59
59
} ;
60
60
}
61
61
62
62
shift ( ) {
63
- if ( ! this . #head ) return null ;
63
+ if ( ! this . _head ) return null ;
64
64
65
- -- this . #length ;
66
- const node = this . #head ;
65
+ -- this . _length ;
66
+ const node = this . _head ;
67
67
if ( node . next ) {
68
68
node . next . previous = node . previous ;
69
- this . #head = node . next ;
69
+ this . _head = node . next ;
70
70
node . next = null ;
71
71
} else {
72
- this . #head = this . #tail = null ;
72
+ this . _head = this . _tail = null ;
73
73
}
74
74
return node . value ;
75
75
}
76
76
77
77
remove ( node : QueueNode < T > ) {
78
- -- this . #length ;
78
+ -- this . _length ;
79
79
80
- if ( this . #tail === node ) {
81
- this . #tail = node . previous ;
80
+ if ( this . _tail === node ) {
81
+ this . _tail = node . previous ;
82
82
}
83
83
84
- if ( this . #head === node ) {
85
- this . #head = node . next ;
84
+ if ( this . _head === node ) {
85
+ this . _head = node . next ;
86
86
} else {
87
87
node . previous ! . next = node . next ;
88
88
node . previous = null ;
@@ -92,7 +92,7 @@ export default class Queue<T> {
92
92
}
93
93
94
94
* [ Symbol . iterator ] ( ) {
95
- let node = this . #head ;
95
+ let node = this . _head ;
96
96
while ( node !== null ) {
97
97
yield node . value ;
98
98
node = node . next ;
0 commit comments