两个栈实现队列
用两个栈实现队列
https://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6?tpId=196&tags=&title=&diffculty=0&judgeStatus=0&rp=1
一个栈A用来保存入队列的数据,另一个栈B用来出队。如果栈B是空的,就需要把栈A全部弹出压入栈B,然后弹出一个元素即可。如果栈B不为空,直接弹出一个元素即可。
Stack<Integer> stack1 = new Stack<Integer>();
    Stack<Integer> stack2 = new Stack<Integer>();
    public void push(int node) {
        stack1.push(node);
    }
    public int pop() {
        if(stack2.size()>0) return stack2.pop();
        while(stack1.size()>0){
            stack2.push(stack1.pop());
        }
        return stack2.pop();
    } 投递思朗科技等公司10个岗位
投递思朗科技等公司10个岗位