/** ****************************************************************************** * HOMEWORK 1, 15-211 ****************************************************************************** * This is an implementation of a dynamic wraparound queue structure. * * It is based on a dynamic array and implements five operation: enqueue, * dequeue, getFront, isEmpty and clear. * * When a queue is first created, it has cap number of items. The * current size of the queue is controled by cur. When cur * reaches cap/tt>,the queue automatically doubles its size. * * Method dequeue and getFront throws an exception on empty queue. * * The contains method runs in amortized constant time. Its implementation * is based the hashtable data structure. * * It implements the Iterator interface for traversing the queue.. * * @author * @date * @see QueueInterface * @see QuadraticProbingHashSet *****************************************************************************/ import java.util.*; public class ArrayQueue implements QueueInterface { private static final int DEFAULT_CAPACITY = 10; private int cap, // total number of elements in the queue cur, // current number of elements front, // front index back; // back index private AnyType[] A; private QuadraticProbingHashSet HT; /* Implement the QueueInterface */ /** * Obtains an Iterator object used to traverse the Queue from its front to back. * @return an iterator. * @throws UnsupportedOperationException if you remove using the iterator */ public Iterator iterator( ) { return new QueueIterator( ); } private class QueueIterator implements Iterator { private int index; //traversal index /* Implement the Iterator interface */ } /* Include the main() for testing and debugging */ /* public static void main(String[] args) { ArrayQueue Q = new ArrayQueue(); String[] people = {"Tom", "Jay", "Pat", "Mark", "Tom", "Victor", "Dan", "John", "Jim"}; // insert the people into the queue for (int i = 0; i < people.length; i++) Q.enqueue(people[i]); // traverse the queue Iterator itr = Q.iterator(); while(itr.hasNext()) System.out.print(itr.next() + " "); System.out.println(); // insert the people into the queue Q.dequeue(); Q.dequeue(); Q.enqueue("1"); Q.enqueue("2"); Q.enqueue("3"); itr = Q.iterator(); while(itr.hasNext()) System.out.print(itr.next()+ " "); System.out.println(); } */ }