https://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6
    思路:将数据从一个栈中捯饬到另一个栈中,模拟队列先进先出。

    1. public class Implementing_queues_with_two_stacks {
    2. static Stack<Integer> stack1 = new Stack<Integer>();
    3. static Stack<Integer> stack2 = new Stack<Integer>();
    4. public static void main(String[] args) {
    5. push(1);
    6. push(2);
    7. System.out.println(pop());
    8. System.out.println(pop());
    9. }
    10. public static void push(int node) {
    11. stack1.push(node);
    12. }
    13. public static int pop() {
    14. while (!stack1.isEmpty()) {
    15. stack2.push(stack1.pop());
    16. }
    17. int ans = stack2.pop();
    18. while (!stack2.isEmpty()) {
    19. stack1.push(stack2.pop());
    20. }
    21. return ans;
    22. }
    23. }