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

pls write a Circular Doubly Linked chain java class that implements the followin

ID: 3804470 • Letter: P

Question

pls write a Circular Doubly Linked chain java class that implements the following interface.

that means the class must have a inner class Node that can indicates previous Node and next Node.

Also, the should be only 1 instance variable which references the firstNode in the class you write.

/**
An interface for the ADT deque.
@author Frank M. Carrano
@author Timothy M. Henry
@version 4.0
*/
public interface DequeInterface
{
/** Adds a new entry to the front/back of this dequeue.
@param newEntry An object to be added. */
public void addToFront(T newEntry);
public void addToBack(T newEntry);

/** Removes and returns the front/back entry of this dequeue.
@return The object at the front/back of the dequeue.
@throws EmptyQueueException if the dequeue is empty before the operation. */
public T removeFront();
public T removeBack();

/** Retrieves the front/back entry of this dequeue.
@return The object at the front/back of the dequeue.
@throws EmptyQueueException if the dequeue is empty before the operation. */
public T getFront();
public T getBack();

/* Detects whether this dequeue is empty.
@return True if the queue is empty, or false otherwise. */
public boolean isEmpty();

/* Removes all entries from this dequeue. */
public void clear();
} // end DequeInterface

Here is an exception class that you may use

/**
A class of runtime exceptions thrown by methods to
indicate that a queue is empty.
@author Frank M. Carrano
@author Timothy M. Henry
*/
public class EmptyQueueException extends RuntimeException
{
public EmptyQueueException()
{
this(null);
} // end default constructor

public EmptyQueueException(String message)
{
super(message);
} // end constructor
} // end EmptyQueueException

Explanation / Answer

public class LinkedDeque implements DequeInterface, java.io.Serializable { private DLNode firstNode; // references node for front of deque private DLNode lastNode; // references node for back of deque public LinkedDeque() { firstNode = null; lastNode = null; } // end default constructor public void addToFront(Object newEntry) { DLNode newNode = new DLNode(null, newEntry, firstNode); if (isEmpty()) lastNode = newNode; else firstNode.setPreviousNode(newNode); firstNode = newNode; } // end addToFront public void addToBack(Object newEntry) { DLNode newNode = new DLNode(lastNode, newEntry, null); if (isEmpty()) firstNode = newNode; else lastNode.setNextNode(newNode); lastNode = newNode; } // end addToBack public Object removeFront() { Object front = null; if (!isEmpty()) { front = firstNode.getData(); firstNode = firstNode.getNextNode(); if (firstNode == null) lastNode = null; else firstNode.setPreviousNode(null); } // end if return front; } // end remove public Object removeBack() { Object back = null; if (!isEmpty()) { back = lastNode.getData(); lastNode = lastNode.getPreviousNode(); if (lastNode == null) firstNode = null; else lastNode.setNextNode(null); } // end if return back; } // end removeBack public Object getFront() { Object front = null; if (!isEmpty()) front = firstNode.getData(); return front; } // end getFront public Object getBack() { Object back = null; if (!isEmpty()) back = lastNode.getData(); return back; } // end getBack public boolean isEmpty() { return firstNode == null && lastNode == null; // both test for debugging } // end isEmpty public void clear() { firstNode = null; lastNode = null; } // end clear private class DLNode implements java.io.Serializable { private Object data; // data portion private DLNode next; // link to next node private DLNode previous; // link to previous node private DLNode(Object dataPortion) { data = dataPortion; next = null; previous = null; } // end constructor private DLNode(DLNode previousNode, Object dataPortion, DLNode nextNode) { data = dataPortion; next = nextNode; previous = previousNode; } // end constructor private Object getData() { return data; } // end getData private void setData(Object newData) { data = newData; } // end setData private DLNode getNextNode() { return next; } // end getNextNode private void setNextNode(DLNode nextNode) { next = nextNode; } // end setNextNode private DLNode getPreviousNode() { return previous; } // end getPreviousNode private void setPreviousNode(DLNode previousNode) { previous = previousNode; } // end setPreviousNode } // end DLNode } // end LinkedDeque