We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 981a98b commit 5156f8dCopy full SHA for 5156f8d
src/_DataStructures_/Stack/2-stacks-using1-array/index.js
@@ -8,6 +8,7 @@ class TwoStacks {
8
this.data = [];
9
this.top1 = -1;
10
this.top2 = capacity;
11
+ this.overflow = new Error('Overflow: Stack is full');
12
13
this.capacity = capacity;
14
}
@@ -16,13 +17,17 @@ class TwoStacks {
16
17
if (this.top1 < this.top2 - 1) {
18
this.top1 += 1;
19
this.data[this.top1] = value;
20
+ } else {
21
+ throw this.overflow;
22
23
24
25
push2(value) {
26
27
this.top2 -= 1;
28
this.data[this.top2] = value;
29
30
31
32
33
0 commit comments