File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ let Queue2 = ( function ( ) {
2
+
3
+ const items = new WeakMap ( ) ;
4
+
5
+ class Queue2 {
6
+
7
+ constructor ( ) {
8
+ items . set ( this , [ ] ) ;
9
+ }
10
+
11
+ enqueue ( element ) {
12
+ let q = items . get ( this ) ;
13
+ q . push ( element ) ;
14
+ items . set ( this , q )
15
+ }
16
+
17
+ dequeue ( ) {
18
+ let q = items . get ( this ) ;
19
+ let r = q . shift ( ) ;
20
+ items . set ( this , q ) ;
21
+ return r ;
22
+ }
23
+
24
+ front ( ) {
25
+ let q = items . get ( this ) ;
26
+ return q [ 0 ] ;
27
+ }
28
+
29
+ isEmpty ( ) {
30
+ return items . get ( this ) . length == 0 ;
31
+ }
32
+
33
+ size ( ) {
34
+ let q = items . get ( this ) ;
35
+ return q . length ;
36
+ }
37
+
38
+ clear ( ) {
39
+ items . set ( this , [ ] ) ;
40
+ }
41
+
42
+ print ( ) {
43
+ console . log ( this . toString ( ) ) ;
44
+ }
45
+
46
+ toString ( ) {
47
+ return items . get ( this ) . toString ( ) ;
48
+ }
49
+ }
50
+ return Queue2 ;
51
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments