Merge pull request #166 from dunera/master

第9题-增加出队为空的判断
This commit is contained in:
CyC2018 2018-04-09 09:29:00 +08:00 committed by GitHub
commit 4bf4b2e1da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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