import java.util.Stack;
public class Dui01 {
private Stack<Integer> stack1=new Stack<>();
private Stack<Integer> stack2=new Stack<>();
public void add(int x){
stack1.push(x);
}
public Integer get(){
Integer re=null;
if(!stack2.empty()){
re=stack2.pop();
}else{
while(!stack1.empty()){
re=stack1.pop();
stack2.push(re);
}
if(!stack2.empty()){
re=stack2.pop();
}
}
return re;
}
}
两个栈组成队列
最新推荐文章于 2024-08-18 00:05:38 发布