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

l1) in java Write a Generic class named Node. The class should hold a field name

ID: 3580794 • Letter: L

Question

l1)

in java Write a Generic class named Node. The class should hold a field named value which will eventually hold a value of some instantiated type. A second field named next will hold a reference to the Node class itself. This class represents nodes that could be used in a singly-linked list. Make sure the class has the following methods :

A constructor that takes two arguments and assigns them into the attributes value and next.

Setters and getters for the two attributes – setNext( ), getNext( ), setValue( ) getValue( ).

Explanation / Answer

Hope this is clear and requires no explanation


public class Node<E> {
  
   private E value;
   private Node<E> next;
  
   public Node(E value, Node<E> next) {
         this.value = value;
         this.next = next;
     }

   public E getValue() {
       return value;
   }

   public void setValue(E value) {
       this.value = value;
   }

   public Node<E> getNext() {
       return next;
   }

   public void setNext(Node<E> next) {
       this.next = next;
   }  
  
}