Package com.Roukan.datastructures.list
Class CircularNode<T>
java.lang.Object
com.Roukan.datastructures.list.CircularNode<T>
- Type Parameters:
T
- the type of value stored in this node
Represents a node in a circular linked list.
Each node contains a value and references to both next and previous nodes,
forming a circular structure where the last node points back to the first.
- Since:
- 2024
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty circular node with null value and null references.CircularNode
(T value) Constructs a new circular node with the specified value and null references. -
Method Summary
Modifier and TypeMethodDescriptiongetNext()
Returns the next node in the circular sequence.Returns the previous node in the circular sequence.getValue()
Returns the value stored in this node.void
setNext
(CircularNode<T> next) Sets the reference to the next node in the circular sequence.void
setPrevious
(CircularNode<T> previous) Sets the reference to the previous node in the circular sequence.void
Sets a new value for this node.toString()
Returns a string representation of this node's value.
-
Constructor Details
-
CircularNode
public CircularNode()Constructs an empty circular node with null value and null references. This constructor creates a node that can be initialized later with setter methods. Useful for placeholder nodes or delayed initialization. -
CircularNode
Constructs a new circular node with the specified value and null references. This constructor is typically used when creating new nodes that will be linked into the circular structure later.- Parameters:
value
- the value to be stored in this node
-
-
Method Details
-
getNext
Returns the next node in the circular sequence. In a properly formed circular list, this should never be null.- Returns:
- the next node in the sequence
-
setNext
Sets the reference to the next node in the circular sequence. This method is used to maintain the circular structure of the list.- Parameters:
next
- the next node in the sequence
-
getPrevious
Returns the previous node in the circular sequence. In a properly formed circular list, this should never be null.- Returns:
- the previous node in the sequence
-
setPrevious
Sets the reference to the previous node in the circular sequence. This method is used to maintain the circular structure of the list.- Parameters:
previous
- the previous node in the sequence
-
getValue
Returns the value stored in this node.- Returns:
- the value stored in this node, may be null if empty constructor was used
-
setValue
Sets a new value for this node.- Parameters:
value
- the new value to be stored in this node
-
toString
Returns a string representation of this node's value. Returns "null" if the value is null, otherwise returns the string representation of the value by calling its toString() method.This method is safe to use even when the value might be null.
-