publicArrayQueue(int initSize) { if (initSize < 0) { thrownewIllegalArgumentException("The init size is less than 0"); } arr = newInteger[initSize]; size = 0; first = 0; last = 0; }
public Integer peek() { if (size == 0) { returnnull; } return arr[first]; }
publicvoidpush(int obj) { if (size == arr.length) { thrownewArrayIndexOutOfBoundsException("The queue is full"); } size++; arr[last] = obj; last = (last == arr.length - 1) ? 0 : last + 1; }