Class Tree.TreeNode<T>

java.lang.Object
util.collection.Tree.TreeNode<T>
Type Parameters:
T - the type of value stored in the node
Enclosing class:
Tree<T>

public static class Tree.TreeNode<T> extends Object
TreeNode represents a node in the tree, holding a value and a list of children.
  • Field Details

    • value

      public final T value
      The value stored in this tree node. It can be of any generic type.
    • children

      public final List<Tree.TreeNode<T>> children
      The list of child nodes of this node. Each element in the list is a Tree.TreeNode representing a subtree. Initially, the list is empty.
  • Constructor Details

    • TreeNode

      public TreeNode(T value)
      Constructs a tree node with the specified value.
      Parameters:
      value - the value to store in the node
  • Method Details

    • addChild

      public void addChild(Tree.TreeNode<T> child)
      Adds a child node to this node.
      Parameters:
      child - the child node to add
    • isLeaf

      public boolean isLeaf()
      Checks if this node is a leaf (has no children).
      Returns:
      true if the node is a leaf, false otherwise