Skip to content

Commit 981a98b

Browse files
committed
fix: removed extra if for throwing error
1 parent 258d4a5 commit 981a98b

File tree

1 file changed

+4
-11
lines changed
  • src/_DataStructures_/Stack/2-stacks-using1-array

1 file changed

+4
-11
lines changed

src/_DataStructures_/Stack/2-stacks-using1-array/index.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,19 @@ class TwoStacks {
1010
this.top2 = capacity;
1111

1212
this.capacity = capacity;
13-
this.total = 0;
1413
}
1514

1615
push1(value) {
17-
if (this.total >= this.capacity + 1) {
18-
throw new Error('Overflow');
19-
}
2016
if (this.top1 < this.top2 - 1) {
2117
this.top1 += 1;
2218
this.data[this.top1] = value;
23-
this.total += 1;
2419
}
2520
}
2621

2722
push2(value) {
28-
if (this.total >= this.capacity + 1) {
29-
throw new Error('Overflow');
30-
}
3123
if (this.top1 < this.top2 - 1) {
3224
this.top2 -= 1;
3325
this.data[this.top2] = value;
34-
this.total += 1;
3526
}
3627
}
3728

@@ -75,13 +66,15 @@ console.log(s.data);
7566
s.push2('b2');
7667
console.log(s.data);
7768
78-
s.push2('b3');
69+
s.push2('d2');
70+
console.log(s.data);
71+
72+
s.push2('c23');
7973
console.log(s.data);
8074
8175
console.log(s.pop2());
8276
console.log(s.data);
8377
8478
console.log(s.pop1());
8579
console.log(s.data);
86-
8780
*/

0 commit comments

Comments
 (0)