Table of Contents

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

TValue

The type of the value that is stored in the node.

TTree

The type of the tree that this type is used in.

TTreeNode

The type of the tree nodes that are used in the TTree type.

Inheritance
BaseTreeNode<TValue, TTree, TTreeNode>
TreeNode<TValue, TTree, TTreeNode>
Implements
ITreeNode<TValue, TTree, TTreeNode>
ITreeNode<TValue>
IEnumerable<TValue>
Derived
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

value TValue

The 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

baseTree TTree

The base tree that contains this node.

value TValue

The 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

parentNode TTreeNode

The parent node.

childrenNodes List<TTreeNode>

The children nodes.

value TValue

The 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

parentNode TTreeNode

The parent node.

value TValue

The 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

int

Height

Gets the height of this tree node's subtree.

public override int Height { get; }

Property Value

int

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

value TValue

The 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

newChild TTreeNode

The 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

values IEnumerable<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

newChildren IEnumerable<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

values 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(params TTreeNode[])

Adds children to the end of this node's children list.

public void AddChildren(params TTreeNode[] newChildren)

Parameters

newChildren TTreeNode[]

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

result TTreeNode

The 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

value TValue

The 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

childToRemove TTreeNode

The child to remove from the children collection.

Returns

bool

true if the child was found and removed, otherwise false.

RegisterAddedChild(TTreeNode)

Performs the operations after a child was added to this tree.

protected override void RegisterAddedChild(TTreeNode addedChild)

Parameters

addedChild TTreeNode

The 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

values IEnumerable<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

childrenToRemove IEnumerable<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

values TValue[]

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

childrenToRemove TTreeNode[]

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.