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