In: Computer Science
complete all methods in java!
/*
Note: Do not add any additional methods,
attributes.
Do not modify the given
part of the program.
Run your program against
the provided Homework2Driver.java for requirements.
*/
/*
Hint: This Queue implementation will always dequeue
from the first element of
the array i.e,
elements[0]. Therefore, remember to shift all elements
toward front of the
queue after each dequeue.
*/
public class QueueArray<T> {
public static int CAPACITY = 100;
private final T[] elements;
private int rearIndex = -1;
public QueueArray() {
}
public QueueArray(int size) {
}
public T dequeue() {
}
public void enqueue(T info) {
}
public boolean isEmpty() {
}
public boolean isFull() {
}
public int size() {
}
}
If you have any doubts, please give me comment...
/*
Note: Do not add any additional methods, attributes.
Do not modify the given part of the program.
Run your program against the provided Homework2Driver.java for requirements.
*/
/*
Hint: This Queue implementation will always dequeue from the first element of
the array i.e, elements[0]. Therefore, remember to shift all elements
toward front of the queue after each dequeue.
*/
public class QueueArray<T> {
public static int CAPACITY = 100;
private final T[] elements;
private int rearIndex = -1;
@SuppressWarnings("unchecked")
public QueueArray() {
elements = (T[]) new Object[CAPACITY];
}
@SuppressWarnings("unchecked")
public QueueArray(int size) {
CAPACITY = size;
elements = (T[]) new Object[size];
}
public T dequeue() {
if(!isEmpty()){
T temp = elements[0];
for (int i = 0; i < rearIndex; i++) {
elements[i] = elements[i + 1];
}
rearIndex--;
return temp;
}
return null;
}
public void enqueue(T info) {
if(!isFull()){
rearIndex++;
elements[rearIndex] = info;
}
}
public boolean isEmpty() {
return rearIndex == -1;
}
public boolean isFull() {
return rearIndex+1 == CAPACITY;
}
public int size() {
return rearIndex+1;
}
}