Package com.Roukan.datastructures.list
Class Node<T>
java.lang.Object
com.Roukan.datastructures.list.Node<T>
- Type Parameters:
T
- the type of value stored in this node
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 -
Method Summary
Modifier and TypeMethodDescriptionReturns the next node in the sequence.getValue()
Returns the value stored in this node.void
setNextNode
(Node<T> nextNode) Sets the reference to the next node in the sequence.void
Sets a new value for this node.toString()
Returns a string representation of this node.
-
Constructor Details
-
Node
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
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 nodenextNode
- the next node in the sequence- Throws:
NullPointerException
- if the value is null (depending on implementation)
-
-
Method Details
-
getValue
Returns the value stored in this node.- Returns:
- the value stored in this node, may be null
-
setValue
Sets a new value for this node.- Parameters:
value
- the new value to be stored in this node
-
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
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
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.
-