|
 |
|
|
|
 |
/**
* Creates a Array Queue which implements all
* of the methods within the Queue interface.
*/
public class ArrayQueue implements Queue {
private Object arrayQueue[];
private int size = 0;
// Constructor takes in a size for the array.
public ArrayQueue(int size) {
arrayQueue = new Object[size];
}
// Adds an object to the Queue.
public void add(Object ob) {
arrayQueue[size++] = ob;
}
/**
* Removes an object from the Queue.
* Keep in mind that Queues follow the FIFO
* (First In First Out) concept.
*/
public Object remove() {
Object start = arrayQueue[0];
for (int k = 0; k < size; k++) {
arrayQueue[k] = arrayQueue[k+1];
}
arrayQueue[size--] = null;
return start;
}
// Retuns the size of the current Queue.
public int size() {
return size;
}
// Returns whether the Queue is full or not.
public boolean isFull(){
return size == arrayQueue.length;
}
// Returns whether the Queue is empty or not.
public boolean isEmpty() {
return size == 0;
}
}
|
| |
|
 |
|
| |
|
|