class CQueue {
private Stack<Integer> in;
private Stack<Integer> out;
public CQueue() {
in = new Stack<Integer>();
out = new Stack<Integer>();
}
public void appendTail(int value) {
in.push(value);
}
public int deleteHead() {
if (!out.isEmpty()) {
return out.pop();
} else {
while (!in.isEmpty()) {
out.push(in.pop());
}
return out.isEmpty() ? -1 : out.pop();
}
}
}
/**
* Your CQueue object will be instantiated and called as such:
* CQueue obj = new CQueue();
* obj.appendTail(value);
* int param_2 = obj.deleteHead();
*/
Sword Finger Offer-1.15-09
Guess you like
Origin blog.csdn.net/Desperate_gh/article/details/112647986
Recommended
Ranking