File tree 1 file changed +4
-11
lines changed
src/_DataStructures_/Stack/2-stacks-using1-array
1 file changed +4
-11
lines changed Original file line number Diff line number Diff line change @@ -10,28 +10,19 @@ class TwoStacks {
10
10
this . top2 = capacity ;
11
11
12
12
this . capacity = capacity ;
13
- this . total = 0 ;
14
13
}
15
14
16
15
push1 ( value ) {
17
- if ( this . total >= this . capacity + 1 ) {
18
- throw new Error ( 'Overflow' ) ;
19
- }
20
16
if ( this . top1 < this . top2 - 1 ) {
21
17
this . top1 += 1 ;
22
18
this . data [ this . top1 ] = value ;
23
- this . total += 1 ;
24
19
}
25
20
}
26
21
27
22
push2 ( value ) {
28
- if ( this . total >= this . capacity + 1 ) {
29
- throw new Error ( 'Overflow' ) ;
30
- }
31
23
if ( this . top1 < this . top2 - 1 ) {
32
24
this . top2 -= 1 ;
33
25
this . data [ this . top2 ] = value ;
34
- this . total += 1 ;
35
26
}
36
27
}
37
28
@@ -75,13 +66,15 @@ console.log(s.data);
75
66
s.push2('b2');
76
67
console.log(s.data);
77
68
78
- s.push2('b3');
69
+ s.push2('d2');
70
+ console.log(s.data);
71
+
72
+ s.push2('c23');
79
73
console.log(s.data);
80
74
81
75
console.log(s.pop2());
82
76
console.log(s.data);
83
77
84
78
console.log(s.pop1());
85
79
console.log(s.data);
86
-
87
80
*/
You can’t perform that action at this time.
0 commit comments