/** * Constructs an empty array queue with an initial capacity * sufficient to hold the specified number of elements. * * @param numElements lower bound on initial capacity of the queue */ public ArrayQueue(int numElements) { allocateElements(numElements); }
/** * Deserialize this queue. */ private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); // Read in size and allocate array int size = s.readInt(); allocateElements(size); head = 0; tail = size; // Read in all elements in the proper order. for (int i = 0; i < size; i++) elements[i] = s.readObject(); } }
/** * Constructs a queue containing the elements of the specified * collection, in the order they are returned by the collection's * iterator. (The first element returned by the collection's * iterator becomes the first element, or <i>front</i> of the * queue.) * * @param c the collection whose elements are to be placed into the queue * @throws NullPointerException if the specified collection is null */ public ArrayQueue(Collection<? extends E> c) { allocateElements(c.size()); addAll(c); }