题目 用两个栈实现一个队列。分别完成在队列尾部插入结点和在队列头部删除结点的功能。 实现 123456789101112131415 Stack<Integer> stack1 = new Stack<Integer>();Stack<Integer> stack2 = new Stack<Integer>();public void (int node) { stack1.push(node);}public int pop() { if (stack2.isEmpty()){ while (!stack1.isEmpty()) stack2.push(stack1.pop()); } return stack2.pop();} 相关题目 用两个队列实现一个栈。 赞微海报分享
近期评论