Assume that a queue of objects is implemented by an array of size N in a circular fashion
Two variables keep track of the front and rear: front and rear, as described in the following class definition.
java code
public class ArrayQueue {
private Object Q[];
private int front,rear;
private int size;
public ArrayQueue(int capacity) {
Q = new Object[capacity];
// variables front and rear are to be initialized here, based // on the requirements below
}
// methods are to be added here based on the requirements below
}
Complete the constructor for ArrayQueue and write the methods enqueue, dequeue, size, front, isEmpty. (Provide a separate solution for each of the following cases.)
1. front is the index of the first element, rear is the index of the last element and the location following the last element is always kept empty.
2. front is the index of the first element, rear is the index of the last element and the location preceding the first element is always kept empty.
3. front is the index of the location preceding the first element, which is always kept empty, rear is the index of the location following the last element, which is always kept empty.
4. . front is the index of the location preceding the first element, which is always kept empty, rear is the index of the last element. (Draw your own picture.)