@@ -0,0 +1,2353 @@
+package week2;%0A%0Aimport java.util.Iterator;%0Aimport java.util.NoSuchElementException;%0A%0A/**%0A * Author: Mark%0A * Date  : 2015/2/27%0A * Time  : 22:12%0A */%0Apublic class Queue%3CItem%3E implements Iterable%3CItem%3E %7B%0A%0A%0A    public static void main(String%5B%5D args) %7B%0A        Queue%3CInteger%3E queue = new Queue%3C%3E();%0A        for (int i = 0; i %3C 10; i++) %7B%0A            queue.enqueue(i);%0A        %7D%0A        System.out.println(queue.size());%0A        System.out.println(queue.isEmpty());%0A        System.out.println(queue.dequeue());%0A        for (int i : queue) %7B%0A            System.out.println(i);%0A        %7D%0A        System.out.println(queue.isEmpty());%0A        System.out.println(queue.size());%0A        while (!queue.isEmpty()) %7B%0A            System.out.println(queue.dequeue());%0A        %7D%0A    %7D%0A%0A%0A    private Node head;%0A    private Node tail;%0A    private int size;%0A%0A    public Queue() %7B%0A        head = null;%0A        tail = null;%0A        size = 0;%0A    %7D%0A%0A    public void enqueue(Item item) %7B%0A        if (isEmpty()) %7B%0A            head = new Node(item);%0A            tail = head;%0A        %7D else %7B%0A            tail.next = new Node(item);%0A            tail = tail.next;%0A        %7D%0A        size++;%0A    %7D%0A%0A    public Item dequeue() %7B%0A        if (isEmpty()) %7B%0A            throw new NoSuchElementException();%0A        %7D%0A        Node node = head;%0A        head = head.next;%0A        node.next = null;%0A        size--;%0A        if (isEmpty()) %7B%0A            tail = head;%0A        %7D%0A        return node.value;%0A    %7D%0A%0A    public boolean isEmpty() %7B%0A        return size == 0;%0A    %7D%0A%0A    public int size() %7B%0A        return size;%0A    %7D%0A%0A    @Override%0A    public Iterator%3CItem%3E iterator() %7B%0A        return new QueueIterator(head);%0A    %7D%0A%0A    private class QueueIterator implements Iterator%3CItem%3E %7B%0A%0A        Node cur;%0A%0A        public QueueIterator(Node cur) %7B%0A            this.cur = cur;%0A        %7D%0A%0A        @Override%0A        public boolean hasNext() %7B%0A            return cur != null;%0A        %7D%0A%0A        @Override%0A        public Item next() %7B%0A            Node res = cur;%0A            cur = cur.next;%0A            return res.value;%0A        %7D%0A%0A        @Override%0A        public void remove() %7B%0A            throw new UnsupportedOperationException();%0A        %7D%0A    %7D%0A%0A%0A    private class Node %7B%0A        Item value;%0A        Node next;%0A%0A        public Node(Item value) %7B%0A            this.value = value;%0A        %7D%0A    %7D%0A%7D%0A

add queue