/**
 * StupidQueue
 * Naive implementation of the Queue abstract data type
 *
 * @author Chris Clifton
 *
 * @recitation mw4 Clifton
 *
 * @date 2/23/2011
 *
 */

class BetterQueue implements Queue {
// Additional constants
  static final int DEFAULTSIZE = 5;
  private int size = 0;
// Instance variables
  private Person q[];
  private int head, tail;
// Constructor
  public BetterQueue(int s) {
    size = s;
    q = new Person[size];
    head = 0;
    tail = 0;
  }
  public BetterQueue() {
    this(DEFAULTSIZE);
  }
// Methods
  public void enqueue ( Person item ) throws Full {
    if (isFull()) throw new Full(head, tail, size);
    q[tail++] = item;
  }
  public Person dequeue() throws Empty {
    if (isEmpty()) throw new Empty();
    return q[head++];
  }
  public boolean isEmpty() {
    return head == tail;
  }
  public boolean isFull() {
    return tail >= size; // Tail ranges from 0 to size-1, need 1 for emptyResult.
  }
}