addFront(T x){ if(isFull()) throw IllegalStateException // queue is full if(headIndex == 0){ headIndex = A.length-1 } else{ headIndex-- } A[headIndex] = x size++ } void addBack(T x){ if(isFull()) throw IllegalStateException // queue is full tailIndex = (tailIndex+1) % A.length; A[tailIndex] = x size++ } T removeFront(){ if(isEmpty()) throw NoSuchElementException // empty queue headValue = A[headIndex] A[headIndex] = null headIndex = (headIndex+1) % A.length size-- return headValue } T removeBack(){ if(isEmpty()) throw NoSuchElementException // empty queue tailValue = A[tailIndex] A[tailIndex] = null if(tailIndex == 0){ tailIndex = A.length-1 } else{ tailIndex-- } size-- return tailValue } getFront(){ if(isEmpty()) throw NoSuchElementException return A[headIndex] } getBack(x){ if(isEmpty()) throw NoSuchElementException else{ return A[tailIndex] } } isFull(){ return (size == capacity) } isEmpty(){ return (size == 0) }