Class TreeNode<TValue, TTree, TTreeNode>
- Namespace
- Garyon.DataStructures.Trees
- Assembly
- Garyon.dll
Represents a tree node, which is a component that is contained within a tree.
public abstract class TreeNode<TValue, TTree, TTreeNode> : BaseTreeNode<TValue, TTree, TTreeNode>, ITreeNode<TValue, TTree, TTreeNode>, ITreeNode<TValue>, IEnumerable<TValue>, IEnumerable where TTree : Tree<TValue, TTree, TTreeNode> where TTreeNode : TreeNode<TValue, TTree, TTreeNode>
Type Parameters
TValueThe type of the value that is stored in the node.
TTreeThe type of the tree that this type is used in.
TTreeNodeThe type of the tree nodes that are used in the
TTreetype.
- Inheritance
-
BaseTreeNode<TValue, TTree, TTreeNode>TreeNode<TValue, TTree, TTreeNode>
- Implements
-
ITreeNode<TValue, TTree, TTreeNode>ITreeNode<TValue>IEnumerable<TValue>
- Derived
-
TreeNode<T>
- Inherited Members
- Extension Methods
Constructors
TreeNode(TValue)
Initializes a new instance of the TreeNode<T> class with no base tree, parent or children nodes.
public TreeNode(TValue value = default)
Parameters
valueTValueThe value of the node.
TreeNode(TTree, TValue)
Initializes a new instance of the TreeNode<T> class with a base tree, but no parent or children nodes.
public TreeNode(TTree baseTree, TValue value = default)
Parameters
baseTreeTTreeThe base tree that contains this node.
valueTValueThe value of the node.
TreeNode(TTreeNode, List<TTreeNode>, TValue)
Initializes a new instance of the TreeNode<T> class with a parent and children nodes. The base tree is considered to be that of the parent.
public TreeNode(TTreeNode parentNode, List<TTreeNode> childrenNodes, TValue value = default)
Parameters
parentNodeTTreeNodeThe parent node.
childrenNodesList<TTreeNode>The children nodes.
valueTValueThe value of the node.
TreeNode(TTreeNode, TValue)
Initializes a new instance of the TreeNode<T> class with a parent node, but no children nodes. The base tree is considered to be that of the parent.
public TreeNode(TTreeNode parentNode, TValue value = default)
Parameters
parentNodeTTreeNodeThe parent node.
valueTValueThe value of the node.
Fields
InternalChildren
The internal children list.
protected List<TTreeNode> InternalChildren
Field Value
- List<TTreeNode>
Properties
BaseTree
Gets or sets the base tree that contains this node.
public override TTree BaseTree { set; }
Property Value
- TTree
Children
Gets or sets the children nodes of this tree. The retrieved list is a copy of the internally stored list, therefore it is best to call this property as less as possible.
public override List<TTreeNode> Children { get; set; }
Property Value
- List<TTreeNode>
The new list of nodes to set the children to. If the list is null, a new list is initialized.
ChildrenCount
Gets the count of children of this node; prefer calling this property instead of getting the count directly from the respective property to retrieve the children.
public override int ChildrenCount { get; }
Property Value
Height
Gets the height of this tree node's subtree.
public override int Height { get; }
Property Value
Parent
Gets or sets the parent node of this tree node.
public override TTreeNode Parent { set; }
Property Value
- TTreeNode
Methods
AddChild(TValue)
Adds a child node that has the specified value to the end of this node's children list.
public TTreeNode AddChild(TValue value)
Parameters
valueTValueThe value of the new child node to add to the end of this node's children list.
Returns
- TTreeNode
The TreeNode<T> that was created and added to this node's children list.
AddChild(TTreeNode)
Adds a child to the end of this node's children list.
public void AddChild(TTreeNode newChild)
Parameters
newChildTTreeNodeThe new child to add to the end of this node's children list.
AddChildren(IEnumerable<TValue>)
Adds child nodes that have the specified values to the end of this node's children list.
public IEnumerable<TTreeNode> AddChildren(IEnumerable<TValue> values)
Parameters
valuesIEnumerable<TValue>The values of the new child nodes to add to the end of this node's children list.
Returns
- IEnumerable<TTreeNode>
The tree nodes that were created and added to this node's children list.
AddChildren(IEnumerable<TTreeNode>)
Adds children to the end of this node's children list.
public void AddChildren(IEnumerable<TTreeNode> newChildren)
Parameters
newChildrenIEnumerable<TTreeNode>The new children to add to the end of this node's children list.
AddChildren(params TValue[])
Adds child nodes that have the specified values to the end of this node's children list.
public IEnumerable<TTreeNode> AddChildren(params TValue[] values)
Parameters
valuesTValue[]The values of the new child nodes to add to the end of this node's children list.
Returns
- IEnumerable<TTreeNode>
The tree nodes that were created and added to this node's children list.
AddChildren(params TTreeNode[])
Adds children to the end of this node's children list.
public void AddChildren(params TTreeNode[] newChildren)
Parameters
newChildrenTTreeNode[]The new children to add to the end of this node's children list.
AddChildrenToClonedInstance(TTreeNode)
Clones this tree node's children to the cloned instance that is created within the Clone() method.
protected override void AddChildrenToClonedInstance(TTreeNode result)
Parameters
resultTTreeNodeThe resulting instance to which to add the cloned children.
Remarks
The cloned children should also be cloned with the Clone(bool) method, but with the argument being false.
GetChild(TValue)
Gets a direct child of this node that has the specified value.
public override TTreeNode GetChild(TValue value)
Parameters
valueTValueThe value of the direct child node to find.
Returns
- TTreeNode
The TreeNode<T> with the specified value, if found; otherwise false.
PerformChildRemoval(TTreeNode)
Performs the removal of a child.
protected override bool PerformChildRemoval(TTreeNode childToRemove)
Parameters
childToRemoveTTreeNodeThe child to remove from the children collection.
Returns
RegisterAddedChild(TTreeNode)
Performs the operations after a child was added to this tree.
protected override void RegisterAddedChild(TTreeNode addedChild)
Parameters
addedChildTTreeNodeThe child that was added to the children collection.
RemoveChildren(IEnumerable<TValue>)
Removes children from this node's children list.
public void RemoveChildren(IEnumerable<TValue> values)
Parameters
valuesIEnumerable<TValue>The values of the children to remove from this node's children list.
RemoveChildren(IEnumerable<TTreeNode>)
Removes children from this node's children list.
public void RemoveChildren(IEnumerable<TTreeNode> childrenToRemove)
Parameters
childrenToRemoveIEnumerable<TTreeNode>The children to remove from this node's children list.
RemoveChildren(params TValue[])
Removes children from this node's children list.
public void RemoveChildren(params TValue[] values)
Parameters
valuesTValue[]The values of the children to remove from this node's children list.
RemoveChildren(params TTreeNode[])
Removes children from this node's children list.
public void RemoveChildren(params TTreeNode[] childrenToRemove)
Parameters
childrenToRemoveTTreeNode[]The children to remove from this node's children list.
TraverseLevelOrderNodes()
Traverses the subtree with this node as a root using level-order. The
nodes are returned with yield return.
public override IEnumerable<TTreeNode> TraverseLevelOrderNodes()
Returns
- IEnumerable<TTreeNode>
An IEnumerable<T> containing the yielded nodes.
TraversePostOrderNodes()
Traverses the subtree with this node as a root using post-order. The
nodes are returned with yield return.
public override IEnumerable<TTreeNode> TraversePostOrderNodes()
Returns
- IEnumerable<TTreeNode>
An IEnumerable<T> containing the yielded nodes.
TraversePreOrderNodes()
Traverses the subtree with this node as a root using pre-order. The
nodes are returned with yield return.
public override IEnumerable<TTreeNode> TraversePreOrderNodes()
Returns
- IEnumerable<TTreeNode>
An IEnumerable<T> containing the yielded nodes.