File tree Expand file tree Collapse file tree 4 files changed +37
-10
lines changed Expand file tree Collapse file tree 4 files changed +37
-10
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -38,4 +38,4 @@ function toString() {
3838 }
3939 }
4040 return retstr ;
41- }
41+ }
Original file line number Diff line number Diff line change 1+ function Stack ( ) {
2+ this . dataStore = [ ]
3+ this . top = 0
4+ this . push = ( element ) => {
5+ this . dataStore [ this . top ++ ] = element
6+ }
7+ this . pop = ( ) => {
8+ return this . dataStore [ -- this . top ]
9+ }
10+ this . peek = ( ) => {
11+ return this . dataStore [ this . top - 1 ]
12+ }
13+ this . length = ( ) => {
14+ return this . top
15+ }
16+ this . clear = ( ) => {
17+ for ( let i = 0 ; i < this . top ; i ++ ) {
18+ this . dataStore . pop ( )
19+ }
20+ this . top = 0
21+ console . log ( this . dataStore , 'data' )
22+ }
23+ }
24+
25+ let st1 = new Stack ( )
26+
27+ st1 . push ( 'nice' )
28+ st1 . push ( 'cool' )
29+ st1 . push ( 'sweet' )
30+ st1 . push ( 'nice' )
31+
32+ console . log ( st1 . dataStore , 'store' )
33+ st1 . clear ( )
34+ console . log ( st1 . dataStore , 'store' )
35+ st1 . push ( 'nice' )
36+ console . log ( st1 . dataStore , 'store' )
You can’t perform that action at this time.
0 commit comments