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