@@ -0,0 +1,1250 @@
+package org.speedfirst.leetcode.not_in_oj;%0A%0Aimport java.util.NoSuchElementException;%0Aimport java.util.Stack;%0A%0A/**%0A * A queue implemented by static%0A * @author jiankuan%0A * @since 1/10/15%0A */%0Apublic class StackBasedQueue %7B%0A%0A    private Stack%3CInteger%3E s1 = new Stack%3C%3E();%0A    private Stack%3CInteger%3E s2 = new Stack%3C%3E();%0A%0A    public void offer(int val) %7B%0A        s1.push(val);%0A    %7D%0A%0A    public int poll() %7B%0A        if (s1.isEmpty() && s2.isEmpty()) %7B%0A            throw new NoSuchElementException();%0A        %7D%0A%0A        if (!s2.isEmpty()) %7B%0A            return s2.pop();%0A        %7D%0A%0A        while (!s1.isEmpty()) %7B%0A            s2.push(s1.pop());%0A        %7D%0A%0A        return s2.pop();%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        StackBasedQueue queue = new StackBasedQueue();%0A        queue.offer(1);%0A        queue.offer(2);%0A        queue.offer(3);%0A        System.out.println(queue.poll());%0A        System.out.println(queue.poll());%0A        queue.offer(4);%0A        queue.offer(5);%0A        System.out.println(queue.poll());%0A        System.out.println(queue.poll());%0A        queue.offer(6);%0A        queue.offer(7);%0A        System.out.println(queue.poll());%0A        System.out.println(queue.poll());%0A        System.out.println(queue.poll());%0A    %7D%0A%7D%0A

add stack based queue