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

View File

@ -393,11 +393,14 @@ public void push(int node) {
in.push(node); in.push(node);
} }
public int pop() { public int pop() throws Exception{
if (out.isEmpty()) { if (out.isEmpty()) {
while (!in.isEmpty()) { while (!in.isEmpty()) {
out.push(in.pop()); out.push(in.pop());
} }
if (out.isEmpty()){
throw new Exception("queue is empty");
}
} }
return out.pop(); return out.pop();
} }