Source of ArrayQueue.java


  1: /**
  2:    A class that implements the ADT queue by using an expandable
  3:    circular array with one unused location.
  4:  
  5:    @author Frank M. Carrano
  6:    @author Timothy M. Henry
  7:    @version 4.0
  8: */
  9: public final class ArrayQueue<T> implements QueueInterface<T>
 10: {
 11:    private T[] queue; // Circular array of queue entries and one unused location
 12:    private int frontIndex;
 13:    private int backIndex;
 14:    private boolean initialized = false;
 15:    private static final int DEFAULT_CAPACITY = 50;
 16:         private static final int MAX_CAPACITY = 10000;
 17:    
 18:    public ArrayQueue()
 19:    {
 20:       this(DEFAULT_CAPACITY);
 21:    } // end default constructor
 22:    
 23:    public ArrayQueue(int initialCapacity)
 24:    {
 25:       checkCapacity(initialCapacity);
 26:       
 27:       // The cast is safe because the new array contains null entries
 28:       @SuppressWarnings("unchecked")
 29:       T[] tempQueue = (T[]) new Object[initialCapacity + 1];
 30:       queue = tempQueue;
 31:       frontIndex = 0;
 32:       backIndex = initialCapacity;
 33:       initialized = true;
 34:    } // end constructor
 35: 
 36: //  < Implementations of the queue operations go here. >
 37: //  . . .
 38:   
 39: } // end ArrayQueue