An array is used to represent a queue:
Initial State: the queue is empty
frontIndex = 0, backIndex = array.length - 1
public void enqueue(T newEntry){
if(array is full)
{double Array;}
backIndex = (backIndex+1) % array.length;
array[backIndex] = newEntry;
}
public T dequeue(){
T entry = array[headIndex];
headIndex = (headIndex + 1) % array.length;
return entry;
}
public boolean isEmpty(){
return frontIndex == (backIndex +1) % array.length'
}
public boolean isFull(){
return frontIndex == (backIndex + 2) % array.length
}