Skip to content

Commit 5156f8d

Browse files
committed
update: thow overflow
1 parent 981a98b commit 5156f8d

File tree

1 file changed

+5
-0
lines changed
  • src/_DataStructures_/Stack/2-stacks-using1-array

1 file changed

+5
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class TwoStacks {
88
this.data = [];
99
this.top1 = -1;
1010
this.top2 = capacity;
11+
this.overflow = new Error('Overflow: Stack is full');
1112

1213
this.capacity = capacity;
1314
}
@@ -16,13 +17,17 @@ class TwoStacks {
1617
if (this.top1 < this.top2 - 1) {
1718
this.top1 += 1;
1819
this.data[this.top1] = value;
20+
} else {
21+
throw this.overflow;
1922
}
2023
}
2124

2225
push2(value) {
2326
if (this.top1 < this.top2 - 1) {
2427
this.top2 -= 1;
2528
this.data[this.top2] = value;
29+
} else {
30+
throw this.overflow;
2631
}
2732
}
2833

0 commit comments

Comments
 (0)