commit
4bf4b2e1da
@ -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();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user