**THIS PROBLEM IS IN JAVA**
If a class is required to store data inside of a node, thegetNode method that exists within the node class is called. It willconfirm the presence of a node in the storage, and make a new nodeis one does not already exist in that storage. That same new nodeis then returned and the amount of nodes is incremented. On theother hand, if the storage list is not empty, the head is separatedfrom the list and updated to store the value of the head as aparameter, and the removed node is returned with the number ofnodes not being incremented. If a value is to be deleted, thereleaseNode method will be called on the node with that value,where it will change the value of the node to null and then placethe node at the head of the storage list.
Node class defined below:
IS NUMNODES STATIC OR NON-STATIC?
COMPLETE A UNIT TEST THAT CONFIRMS THE NUMBER OF NODES ISCORRECT WHEN CALLING GETNODE. WRITE ANOTHER UNIT TEST THAT CONFIRMSTHE VALUE OF A NODE IS CHANGED TO NULL AFTER RELEASENODE ISCALLED.
COMPLETE A UNIT TEST THAT CONFIRMS THE NUMBER OF NODES ISCORRECT WHEN CALLING GETNODE AFTER RELEASENODE.
public class Node<E> { private E e; // Value for this node private Node<E> next; // Point to next node in list // Constructor Node (E it, Node<E> inn) { e = it; next = inn; } public E element () { return e; } // Return the value public void setElement (E it) { e = it; } // Set element value public Node<E> next () { return next; } // Return next node public void setNext (Node<E> inn) { next = inn; } // Set next node. *****/ * Extensions to support storage list **/ private static Node storagelist = null; // storage list for the class. // define the number of nodes created // TO DO /** *Return a new node, from storage list if it is not empty * @param it - the value to be stored in the new node * @param inn - the follower of the new node * @return the node is empty, a new node is created, if not the head of the * storage list is used to store it **/ public static <E> Node <E> getNode (E it, Node<E> inn) { // TODO } * containing the value it. If the storage list // Return a node to the storage list public void releaseNode () { // TODO } // int get NumNodes () : Return the number of nodes created // TODO To create a new node of String (without a follower node) we write Node <String> n = Node.getNode ("Hello", null); and to release that same node we write n. release ();
**THIS PROBLEM IS IN JAVA** If a class is required to store data inside of a node, the getNode method that exists within
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am