001// Exercise 1.3.29
002package algs13;
003import stdlib.*;
004import java.util.Iterator;
005
006public class MyQueueCircular<T> implements Iterable<T> {
007        private int N; // number of elements on queue
008        private Node<T> last; // end of queue
009
010        // helper linked list class
011        private static class Node<T> {
012                public Node() { }
013                public T item;
014                public Node<T> next;
015        }
016
017        public MyQueueCircular () {}
018
019        public boolean isEmpty () {
020                return false;
021        }
022
023        public int size () {
024                return 0;
025        }
026
027        public T peek () {
028                return null;
029        }
030
031        public void enqueue (T item) {}
032
033        public T dequeue () {
034                return null;
035        }
036
037        public String toString () {
038                return null;
039        }
040
041        public Iterator<T> iterator () {
042                return new QueueIterator ();
043        }
044
045        // an iterator, doesn't implement remove() since it's optional
046        private class QueueIterator implements Iterator<T> {
047                public boolean hasNext () {
048                        return false;
049                }
050                public T next () {
051                        return null;
052                }
053                public void remove () {}
054        }
055
056        /**
057         * A test client.
058         */
059        public static void main (String[] args) {
060                MyQueueCircular<String> q = new MyQueueCircular<> ();
061                while (!StdIn.isEmpty ()) {
062                        String item = StdIn.readString ();
063                        if (!item.equals ("-")) q.enqueue (item);
064                        else if (!q.isEmpty ()) StdOut.print (q.dequeue () + " ");
065                }
066                StdOut.println ("(" + q.size () + " left on queue)");
067        }
068}