Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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‎

Lines changed: 5 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /