public class ArrayPureQueue implements PureQueue // Note: does not implement Collection { protected E [ ] data; protected int size, head, tail; /** * Determines the number of elements in this PureQueue object. * * @return the number of elements in this PureQueue object. * */ public int size() { } /** * Determines if this PureQueue object has no elements. * * @return true - if this PureQueue object has no elements; otherwise, * return false. * */ public boolean isEmpty() { } /** * Inserts a specified element at the back of this PureQueue object. * The averageTime(n) is constant and worstTime(n) is O(n). * * @param element - the element to be appended. * */ public void enqueue (E element) { if (size == data.length) { // double the length of data E [ ] oldData = data; data = (E [ ]) new Object [data.length * 2]; // copy oldData [head...oldData.length-1] to data [0...oldData.length-1 - head] System.arraycopy (oldData, head, data, 0, oldData.length - head); if (head > 0) // copy oldData [0...tail] to data [oldData.length - head...oldData.length-1] System.arraycopy (oldData, 0, data, oldData.length - head, tail+1); head = 0; tail = oldData.length - 1; } // if this ArrayPureQueue object occupies all of data tail = (tail + 1) % data.length; size++; data [tail] = element; } // method enqueue /** * Removes the front element from this PureQueue object. * * @return - the element removed. * * @throws NoSuchElementException - if this PureQueue object is empty. * */ public E dequeue() { } /** * Returns the front element in this PureQueue object. * * @return - the element returned. * * @throws NoSuchElementException - if this PureQueue object is empty. * */ public E front() { } } // class ArrayPureQueue