A Queue is a first-in-first-out collection of objects. An example of a queue is a line of waiting at a traffic light. The first car that arrived will be the first that leaves when the light turns green. New cars arriving are added to the end of the line. Then all cars will leave in the order they arrived.
I have created a class called ArrayQueue which implements a Queue. It has a contructor and three methods:
public ArrayQueue(int maxLength)
public void insert(Object o)
public Object remove()
public int getLength()
Note the limitations of this array-based implementation of a Queue.
getHead()
method might be nice to do this.
isEmpty()
method which
returns true
or false
if we have removed all
of the items from the Queue (or never added any). This way users of
this class would be able to check to make sure they didn't attempt to
remove objects from an empty Queue:
do { /* process each object */ } until ( queue.isEmpty() );