buildEmptyDoubleThis method should return an empty doublylin

buildEmptyDouble()-This method should return an empty doubly-linked list (a linked list of length 0)

buildListWith5Strings()-This method should return the first node in the linked list

buildListWith5Doubles()-This method should return the first node in the linked list

***********************************************

package code;

public class DNode {

private E element;

private DNode previous;

public DNode() {

next = null;

element = null;

previous = null;

} /**

* Creates a node storing the specified element. *

* @param elem Element to which the new node should refer

*/

public DNode(E elem) {

next = null;

previous = null;

element = elem;

}

/**

* Get the next node in the linked list. *

* @return Reference to the node following this one

*/

public DNode getNext() {

return next;

}

/**

* Specify that the given node should be before the current one in the linked

* list. *

* @param node node which should come before the current one

*/

public void setPrevious(DNode node) {

previous = node;

}

/**

* Get the previous node in the linked list. *

*@return Reference to the node before this one */

public DNode getPrevious() {

return previous;

}

/** * Specify that the given node should follow the current one in the linked * list. * * @param node node which should follow the current one */

public void setNext(DNode node) {

next = node;

}

/** * Get the element stored within this node. *

* @return Element referred to by the node */

public E getElement() {

return element;

}

/** * Direct the node to store a new element. * * @param elem New element which this node should store */

public void setElement(E elem) {

element = elem;

}

}

*****************************************************************************************************

package code;

public static DNode buildEmptyDouble() {

DNode retVal;

}

/** * This method should instantiate and return a doubly-linked list with 5 elements. In

* order, the elements should be the Strings \"Hi\", \"Mom\", \"I\'m\", \"in\", \"Jail\".

* .You will need to instantiate

* and connect any DNode instances yourself. *

* @return Doubly-linked list that contains the 5 Strings in proper order */

public static DNode buildListWith5Strings() {

DNode retVal;

}

/**

* This method should instantiate and return a doubly-linked list with 5 elements. In

* order, the elements should be the Doubles 4.6, -2.3, 273.15, 3.1415, 42.0.

* You will need to instantiate and connect any DNode instances yourself. *

* @return Doubly-linked list that contains the 5 Doubles in proper order

*/

public static DNode buildListWith5Doubles() {

DNode retVal;

}

}

Solution

Hi, Please find implementation of methods.


public static DNode buildListWith5Strings() {

   // creating head node
   DNode headNode = new DNode(\"Hi\");

   // creating second node
   DNode second = new DNode(\"Mom\");

   // creating third node
   DNode third = new DNode(\"I\'m\");
   DNode fourth = new DNode(\"in\"); // creating fourth node
   DNode fifth = new DNode(\"Jail\"); // creating fifth node

   // setting previous and next of head node
   headNode.setPrevious(null);
   headNode.setNext(second);
   // setting previous and next of second node
   second.setPrevious(headNode);
   second.setNext(third);
   // setting previous and next of third node
   third.setPrevious(second);
   third.setNext(fourth);
   // setting previous and next of fourth node
   fourth.setPrevious(third);
   fourth.setNext(fifth);
   // setting previous and next of fifth node
   fifth.setPrevious(fourth);
   fifth.setNext(null);

   return headNode;
}

public static DNode buildListWith5Doubles() {
   4.6, -2.3, 273.15, 3.1415, 42.0.

   // creating head node
   DNode headNode = new DNode(4.6);

   // creating second node
   DNode second = new DNode(-2.3);

   // creating third node
   DNode third = new DNode(273.15);
   DNode fourth = new DNode(3.1415); // creating fourth node
   DNode fifth = new DNode(42.0); // creating fifth node

   // setting previous and next of head node
   headNode.setPrevious(null);
   headNode.setNext(second);
   // setting previous and next of second node
   second.setPrevious(headNode);
   second.setNext(third);
   // setting previous and next of third node
   third.setPrevious(second);
   third.setNext(fourth);
   // setting previous and next of fourth node
   fourth.setPrevious(third);
   fourth.setNext(fifth);
   // setting previous and next of fifth node
   fifth.setPrevious(fourth);
   fifth.setNext(null);

   return headNode;
}

buildEmptyDouble()-This method should return an empty doubly-linked list (a linked list of length 0) buildListWith5Strings()-This method should return the first
buildEmptyDouble()-This method should return an empty doubly-linked list (a linked list of length 0) buildListWith5Strings()-This method should return the first
buildEmptyDouble()-This method should return an empty doubly-linked list (a linked list of length 0) buildListWith5Strings()-This method should return the first
buildEmptyDouble()-This method should return an empty doubly-linked list (a linked list of length 0) buildListWith5Strings()-This method should return the first

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site