can you please explain how to complete all methods in
java ?
thanks
/*
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() {
}
}
public class QueueArray<T> {
public static int CAPACITY = 100;
private final T[] elements;
private int rearIndex = -1;
public QueueArray() {
elements = (T[])new
Object[CAPACITY];
}
public QueueArray(int size) {
CAPACITY =size;
elements = (T[])new Object[CAPACITY];
}
public T dequeue() {
if(isEmpty())return null;
else
{
T t = elements[0];
int i=0;
while(i< rearIndex )//moving front
{
elements[i]=elements[i+1];
i++;
}
rearIndex -=1;//decreasing rear index
return t;
}
}
public void enqueue(T info) {
if(!isFull()){
elements[ rearIndex +1]=info;
rearIndex +=1;
}
}
public boolean isEmpty() {
if( rearIndex ==-1)return true;
return false;
}
public boolean isFull() {
if( rearIndex +1 == CAPACITY)return true;
return false;
}
public int size() {
return rearIndex +1;
}
}
Get Answers For Free
Most questions answered within 1 hours.