Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;

Removes and returns the element that is at place x in the queue. Precondition: x must be less than 5, x must be less than size * Note: indexing from 0: 0-front element, I =-second element, etc. eparam x the passed in index of the element to be removed @return the element removed from the queue throws EmptyCollectionException if the queue is empty @throws InvalidArgumentException if x 4, orx size of collection public T dequeue (int x) throws EmptyCollectionException, InvalidArgumentException;

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;

   }