mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
Modify the exception handling in Java and Python.
This commit is contained in:
@@ -35,14 +35,14 @@ class ArrayStack {
|
||||
/* 出栈 */
|
||||
public int pop() {
|
||||
if (isEmpty())
|
||||
throw new EmptyStackException();
|
||||
throw new IndexOutOfBoundsException();
|
||||
return stack.remove(size() - 1);
|
||||
}
|
||||
|
||||
/* 访问栈顶元素 */
|
||||
public int peek() {
|
||||
if (isEmpty())
|
||||
throw new EmptyStackException();
|
||||
throw new IndexOutOfBoundsException();
|
||||
return stack.get(size() - 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user