提交 0f2ee44a 编写于 作者: D dunera

第9题-增加出队为空的判断

上级 e287699d
......@@ -393,11 +393,14 @@ public void push(int node) {
in.push(node);
}
public int pop() {
public int pop() throws Exception{
if (out.isEmpty()) {
while (!in.isEmpty()) {
out.push(in.pop());
}
if (out.isEmpty()){
throw new Exception("queue is empty");
}
}
return out.pop();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册