import java.util.Stack;

/**
 * Created by Administrator on 2017/3/3.
 */


class Queue<T> {
    public Stack<T> stack1;
    public Stack<T> stack2;

    public Queue() {
        stack1 = new Stack<T>();
        stack2 = new Stack<T>();
    }

    public void appendTail(T element) {
        stack1.push(element);
    }
    public T deleteHead() {
        if (stack2.size() <= 0) {
            while (stack1.size() > 0) {
                T element = stack1.peek();
                stack1.pop();
                stack2.push(element);
            }
        }

        if (stack2.size() == 0)
            return null;
        T head = stack2.peek();
        stack2.pop();
        return head;
    }
}

public class QueueWithTwoStacks<T> {
    public Queue<T> queue;

    public static void main (String[] args) {
        QueueWithTwoStacks<Integer> q = new QueueWithTwoStacks<>();
        q.queue = new Queue<Integer>();
        for (int i = 0; i < 10; i++) {
            q.queue.appendTail(i);
        }
        for (int i = 0; i < 10; i++) {
            int element = q.queue.deleteHead();
            System.out.print(element + " ");
        }
    }
}




@@ -309,24 +309,73 @@
 ent);%0A    %7D%0A
+    // %E5%88%A4%E6%96%ADstack2%E7%9A%84%E7%8A%B6%E6%80%81%EF%BC%8C%E9%9D%9E%E7%A9%BA%E7%9B%B4%E6%8E%A5%E5%BC%B9%E5%87%BA%EF%BC%8C%E7%A9%BA%E5%88%99%E5%B0%86stack1%E6%89%80%E6%9C%89%E7%9A%84%E5%85%83%E7%B4%A0%E5%8E%8B%E5%85%A5stack2%0A
     public T

Create 007_QueueWithTwoStacks.java