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

This commit is contained in:
dunera 2018-04-09 00:19:15 +08:00
parent e287699d38
commit 0f2ee44ad7

View File

@ -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();
}