public class Queue {
public Queue () {
myValues = new int[100];
}
public Queue (int max_size) {
myValues = new int[max_size+1];
}
public void add (int item)
throws QueueException
{
if (((myHead+1) % myValues.length) == myTail) {
throw new QueueException();
}
myValues[myHead] = item;
myHead = (myHead + 1) % myValues.length;
}
public int get ()
throws QueueException
{
if (myHead == myTail) {
throw new QueueException();
}
int result = myValues[myTail];
myTail = (myTail + 1) % myValues.length;
return result;
}
public boolean isFull () {
return ((myHead+1) % myValues.length) == myTail;
}
public boolean isEmpty () {
return myHead == myTail;
}
private int myHead = 0;
private int myTail = 0;
private int myValues[];
}
|