I just need a java mehod that follows the Javadocs Implented using an arraylist.
ID: 3596274 • Letter: I
Question
I just need a java mehod that follows the Javadocs Implented using an arraylist.
public class WorkAheadQueue<T> implements WorkAheadQueueADT<T> {
private LinearNode<T> front;
private LinearNode<T> back;
private int numNodes;
private ArrayList<LinearNode<T>> frontFive;
Explanation / Answer
Hi friend, You have not posted whole class structure.
PLease find my implementation.
public T dequeue(int x) throws EmptyCollectionException, InvalidArgumentException {
if(numNodes == 0)
throw new EmptyCollectionException();
if( x > 4 || x > numNodes) {
throw new InvalidArgumentException();
}
LinearNode<T> t = null;
if(x == 0){
t = front;
if(numNodes == 1)
back = null;
numNodes = 0;
front = front.getNext();
}else if(x == numNodes-1){
t = back;
back = frontFive.get(x-1);
frontFive.get(x-1).setNext(null);
numNodes--;
}
return t;
}