Table of Contents

Class BinaryTreeNode<TValue, TTree, TTreeNode>

Namespace
Garyon.DataStructures.Trees
Assembly
Garyon.dll

Represents a binary tree node, which is a component that is contained within a binary tree.

public abstract class BinaryTreeNode<TValue, TTree, TTreeNode> : BaseTreeNode<TValue, TTree, TTreeNode>, ITreeNode<TValue, TTree, TTreeNode>, ITreeNode<TValue>, IEnumerable<TValue>, IEnumerable where TTree : BinaryTree<TValue, TTree, TTreeNode> where TTreeNode : BinaryTreeNode<TValue, TTree, TTreeNode>

Type Parameters

TValue

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

TTree

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

TTreeNode

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

Inheritance
BaseTreeNode<TValue, TTree, TTreeNode>
BinaryTreeNode<TValue, TTree, TTreeNode>
Implements
ITreeNode<TValue, TTree, TTreeNode>
ITreeNode<TValue>
IEnumerable<TValue>
Derived
Inherited Members
Extension Methods

Constructors

BinaryTreeNode(TValue)

Initializes a new instance of the BinaryTreeNode<T> class with no base tree, parent or children nodes.

public BinaryTreeNode(TValue value = default)

Parameters

value TValue

The value of the node.

BinaryTreeNode(TTree, TValue)

Initializes a new instance of the BinaryTreeNode<T> class with a base tree, but no parent or children nodes.

public BinaryTreeNode(TTree baseTree, TValue value = default)

Parameters

baseTree TTree

The base tree that contains this node.

value TValue

The value of the node.

BinaryTreeNode(TTreeNode, TValue)

Initializes a new instance of the BinaryTreeNode<T> class with a parent node, but no children nodes. The base tree is considered to be that of the parent.

public BinaryTreeNode(TTreeNode parentNode, TValue value = default)

Parameters

parentNode TTreeNode

The parent node.

value TValue

The value of the node.

BinaryTreeNode(TTreeNode, TTreeNode, TTreeNode, TValue)

Initializes a new instance of the BinaryTreeNode<T> class with a parent and children nodes. The base tree is considered to be that of the parent.

public BinaryTreeNode(TTreeNode parentNode, TTreeNode leftChild, TTreeNode rightChild, TValue value = default)

Parameters

parentNode TTreeNode

The parent node.

leftChild TTreeNode

The left child node.

rightChild TTreeNode

The right child node.

value TValue

The value of the node.

Fields

InternalLeftChild

The left child of this node. This internal field is exposed to avoid using the property setters.

protected TTreeNode InternalLeftChild

Field Value

TTreeNode

InternalRightChild

The right child of this node. This internal field is exposed to avoid using the property setters.

protected TTreeNode InternalRightChild

Field Value

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 new list created based on the left and right children of this node, 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 sealed int ChildrenCount { get; }

Property Value

int

Height

Gets the height of this tree node's subtree.

public override sealed int Height { get; }

Property Value

int

LeftChild

The left child of this node.

public virtual TTreeNode LeftChild { get; set; }

Property Value

TTreeNode

Parent

Gets or sets the parent node of this tree node.

public override TTreeNode Parent { set; }

Property Value

TTreeNode

RightChild

The right child of this node.

public virtual TTreeNode RightChild { get; 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 BinaryTreeNode<T> that was created and added to this node's children list.

AddChild(TTreeNode)

Adds a child to the first available spot from the two children spots.

public virtual void AddChild(TTreeNode newChild)

Parameters

newChild TTreeNode

The new child to add.

AddChildren(TValue, TValue)

Adds children to the available spots from the two children spots. If both are unoccupied, both values are added in the provided order, otherwise only the left is added, if there is any unoccupied spot.

public void AddChildren(TValue left, TValue right)

Parameters

left TValue

The value of the left child to add.

right TValue

The value of the right child to add.

AddChildren(TTreeNode, TTreeNode)

Adds children to the available spots from the two children spots. If both are unoccupied, both nodes are added in the provided order, otherwise only the left is added, if there is any unoccupied spot.

public virtual void AddChildren(TTreeNode left, TTreeNode right)

Parameters

left TTreeNode

The left child to add.

right TTreeNode

The right child to add.

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 the leftmost 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 BinaryTreeNode<T> with the specified value, if found; otherwise null.

PerformChildRemoval(TTreeNode)

Performs the removal of a child.

protected override sealed 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 sealed 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.

TraverseInOrder()

Traverses the subtree with this node as a root using pre-order. The elements are returned with yield return.

public IEnumerable<TValue> TraverseInOrder()

Returns

IEnumerable<TValue>

The yielded values.

TraverseInOrderNodes()

Traverses the subtree with this node as a root using in-order. The nodes are returned with yield return.

public IEnumerable<TTreeNode> TraverseInOrderNodes()

Returns

IEnumerable<TTreeNode>

The yielded nodes.

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>

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>

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>

The yielded nodes.