Class Node<T>

java.lang.Object
com.Roukan.datastructures.list.Node<T>
Type Parameters:
T - the type of value stored in this node

public class Node<T> extends Object
Represents a node in a singly linked list. Each node contains a value and a reference to the next node in the sequence.
Since:
2024
  • Constructor Summary

    Constructors
    Constructor
    Description
    Node(T value)
    Constructs a new node with the specified value and no next node.
    Node(T value, Node<T> nextNode)
    Constructs a new node with the specified value and next node reference.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the next node in the sequence.
    Returns the value stored in this node.
    void
    setNextNode(Node<T> nextNode)
    Sets the reference to the next node in the sequence.
    void
    setValue(T value)
    Sets a new value for this node.
    Returns a string representation of this node.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Node

      public Node(T value)
      Constructs a new node with the specified value and no next node. This constructor is typically used for creating the last node in a list.
      Parameters:
      value - the value to be stored in this node
      Throws:
      NullPointerException - if the value is null (depending on implementation)
    • Node

      public Node(T value, Node<T> nextNode)
      Constructs a new node with the specified value and next node reference. This constructor is used for creating nodes that are not at the end of the list.
      Parameters:
      value - the value to be stored in this node
      nextNode - the next node in the sequence
      Throws:
      NullPointerException - if the value is null (depending on implementation)
  • Method Details

    • getValue

      public T getValue()
      Returns the value stored in this node.
      Returns:
      the value stored in this node, may be null
    • setValue

      public void setValue(T value)
      Sets a new value for this node.
      Parameters:
      value - the new value to be stored in this node
    • getNextNode

      public Node<T> getNextNode()
      Returns the next node in the sequence. If this node is the last one in the list, returns null.
      Returns:
      the next node in the sequence, or null if this is the last node
    • setNextNode

      public void setNextNode(Node<T> nextNode)
      Sets the reference to the next node in the sequence. Use null to indicate that this node is the last one in the list.
      Parameters:
      nextNode - the next node in the sequence, or null to make this the last node
    • toString

      public String toString()
      Returns a string representation of this node. The format is "Node{value}" where value is the string representation of the stored value. If the value is null, returns "Node{null}".

      This method is primarily intended for debugging purposes.

      Overrides:
      toString in class Object
      Returns:
      a string representation of this node