package com.matao;

/**
 * Created by matao on 2018-12-07.
 */
public class Q09_QueueWith2Stacks {
}

@@ -17,85 +17,662 @@
 o;%0A%0A
-/**%0A * Created by matao on 2018-12-07.%0A */%0Apublic class Q09_QueueWith2Stacks %7B
+import com.matao.common.EmptyQueueException;%0A%0Aimport java.util.Stack;%0A%0A/**%0A * Created by matao on 2018-12-07.%0A * %3Cp%3E%0A * %E7%94%A8%E4%B8%A4%E4%B8%AA%E6%A0%88%EF%BC%8C%E5%AE%9E%E7%8E%B0%E9%98%9F%E5%88%97%E7%9A%84%E4%BB%8E%E9%98%9F%E5%B0%BE%E6%8F%92%E5%85%A5%E5%85%83%E7%B4%A0 enqueue() %E5%92%8C%E4%BB%8E%E9%98%9F%E5%A4%B4%E6%8A%9B%E5%87%BA%E5%85%83%E7%B4%A0 dequeue()%0A */%0Apublic class Q09_QueueWith2Stacks%3CE%3E %7B%0A%0A    private Stack%3CE%3E stack1 = new Stack%3C%3E();%0A    private Stack%3CE%3E stack2 = new Stack%3C%3E();%0A%0A    public void enqueue(E item) %7B%0A        stack1.push(item);%0A    %7D%0A%0A    public E dequeue() %7B%0A        if (stack2.isEmpty()) %7B%0A            while (!stack1.isEmpty()) %7B%0A                stack2.push(stack1.pop());%0A            %7D%0A        %7D%0A        if (stack2.isEmpty()) %7B%0A            throw new EmptyQueueException();%0A        %7D%0A        return stack2.pop();%0A    %7D
 %0A%7D%0A

add Q09 QueueWith2Stacks