Table of Contents

Class BinaryTree<TValue, TTree, TTreeNode>

Namespace
Garyon.DataStructures.Trees
Assembly
Garyon.dll

Represents a binary tree.

public abstract class BinaryTree<TValue, TTree, TTreeNode> : BaseTree<TValue, TTree, TTreeNode>, ITree<TValue, TTree, TTreeNode>, ITree<TValue>, ICollection<TValue>, IEnumerable<TValue>, IEnumerable where TTree : BinaryTree<TValue, TTree, TTreeNode> where TTreeNode : BinaryTreeNode<TValue, TTree, TTreeNode>

Type Parameters

TValue

The type of the elements the binary tree nodes store.

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
BaseTree<TValue, TTree, TTreeNode>
BinaryTree<TValue, TTree, TTreeNode>
Implements
ITree<TValue, TTree, TTreeNode>
ITree<TValue>
ICollection<TValue>
IEnumerable<TValue>
Derived
Inherited Members
Extension Methods

Constructors

BinaryTree()

Initializes a new instance of the BinaryTree<TValue, TTree, TTreeNode> class with no root node.

protected BinaryTree()

BinaryTree(TValue)

Initializes a new instance of the BinaryTree<TValue, TTree, TTreeNode> class with a root value.

protected BinaryTree(TValue rootValue)

Parameters

rootValue TValue

The value of the root node.

BinaryTree(TTree)

Initializes a new instance of the BinaryTree<TValue, TTree, TTreeNode> class from a different tree.

protected BinaryTree(TTree tree)

Parameters

tree TTree

The tree to create this tree from. Both trees remain independent.

BinaryTree(TTreeNode)

Initializes a new instance of the BinaryTree<TValue, TTree, TTreeNode> class with a root node.

protected BinaryTree(TTreeNode root)

Parameters

root TTreeNode

The root node.

Methods

AddChild(TTreeNode, TValue, bool)

Adds a child to a node within this tree.

public void AddChild(TTreeNode node, TValue value, bool propagate = true)

Parameters

node TTreeNode

The parent node whose children to set. The node must be within this tree.

value TValue

The value of the new child to add to the node.

propagate bool

Determines whether this function should propagate to the AddChild(TTreeNode) function. Only set this to false if the new child was already added before calling this function.

AddChild(TTreeNode, TTreeNode, bool)

Adds a child to a node within this tree.

public void AddChild(TTreeNode node, TTreeNode newChild, bool propagate = true)

Parameters

node TTreeNode

The parent node whose children to set. The node must be within this tree.

newChild TTreeNode

The new child to add to the node.

propagate bool

Determines whether this function should propagate to the AddChild(TTreeNode) function. Only set this to false if the new child was already added before calling this function.

AddChildren(TTreeNode, TTreeNode, TTreeNode, bool)

Adds children to a node within this tree.

public void AddChildren(TTreeNode node, TTreeNode leftChild, TTreeNode rightChild, bool propagate = true)

Parameters

node TTreeNode

The parent node whose children to add. The node must be within this tree.

leftChild TTreeNode

The left child to add to the node.

rightChild TTreeNode

The right child to add to the node.

propagate bool

Determines whether this function should propagate to the AddChildren(TTreeNode, TTreeNode) function. Only set this to false if the new child was already added before calling this function.

ClearChildren(TTreeNode, bool)

Clears the children of a node within this tree.

public override void ClearChildren(TTreeNode node, bool propagate = true)

Parameters

node TTreeNode

The parent node whose children to clear. The node must be within this tree.

propagate bool

Determines whether this function should propagate to the Children property. Only set this to false if the new children are already set in the node before calling this function.

RemoveChildren(TValue, IEnumerable<TValue>, bool)

Removes children from a node within this tree.

public void RemoveChildren(TValue value, IEnumerable<TValue> childrenToRemove, bool propagate = true)

Parameters

value TValue

The parent node whose children to add. The node must be within this tree.

childrenToRemove IEnumerable<TValue>

The children to remove from the node.

propagate bool

Determines whether this function should propagate to the RemoveChildren(IEnumerable<TValue>) function. Only set this to false if the new child was already added before calling this function.

RemoveChildren(TValue, IEnumerable<TTreeNode>, bool)

Removes children from a node within this tree.

public void RemoveChildren(TValue value, IEnumerable<TTreeNode> childrenToRemove, bool propagate = true)

Parameters

value TValue

The parent node whose children to add. The node must be within this tree.

childrenToRemove IEnumerable<TTreeNode>

The children to remove from the node.

propagate bool

Determines whether this function should propagate to the RemoveChildren(IEnumerable<TTreeNode>) function. Only set this to false if the new child was already added before calling this function.

RemoveChildren(TTreeNode, IEnumerable<TValue>, bool)

Removes children from a node within this tree.

public void RemoveChildren(TTreeNode node, IEnumerable<TValue> childrenToRemove, bool propagate = true)

Parameters

node TTreeNode

The parent node whose children to add. The node must be within this tree.

childrenToRemove IEnumerable<TValue>

The children to remove from the node.

propagate bool

Determines whether this function should propagate to the RemoveChildren(IEnumerable<TValue>) function. Only set this to false if the new child was already added before calling this function.

RemoveChildren(TTreeNode, IEnumerable<TTreeNode>, bool)

Removes children from a node within this tree.

public void RemoveChildren(TTreeNode node, IEnumerable<TTreeNode> childrenToRemove, bool propagate = true)

Parameters

node TTreeNode

The parent node whose children to add. The node must be within this tree.

childrenToRemove IEnumerable<TTreeNode>

The children to remove from the node.

propagate bool

Determines whether this function should propagate to the RemoveChildren(IEnumerable<TTreeNode>) function. Only set this to false if the new child was already added before calling this function.

RemoveRootChildren(IEnumerable<TValue>, bool)

Removes this tree's root direct children.

public void RemoveRootChildren(IEnumerable<TValue> childrenToRemove, bool propagate = true)

Parameters

childrenToRemove IEnumerable<TValue>

The children to remove from the tree root node.

propagate bool

Determines whether this function should propagate to the RemoveChildren(IEnumerable<TTreeNode>) function. Only set this to false if the new child was already added before calling this function.

RemoveRootChildren(IEnumerable<TTreeNode>, bool)

Removes this tree's root direct children.

public void RemoveRootChildren(IEnumerable<TTreeNode> childrenToRemove, bool propagate = true)

Parameters

childrenToRemove IEnumerable<TTreeNode>

The children to remove from the tree root node.

propagate bool

Determines whether this function should propagate to the RemoveChildren(IEnumerable<TTreeNode>) function. Only set this to false if the new child was already added before calling this function.

SetChildren(TValue, TTreeNode, TTreeNode, bool)

Sets the children of a node within this tree.

public void SetChildren(TValue value, TTreeNode leftChild, TTreeNode rightChild, bool propagate = true)

Parameters

value TValue

The value of the parent node whose children to set. The node must be within this tree.

leftChild TTreeNode

The left child to set to the node.

rightChild TTreeNode

The right child to set to the node.

propagate bool

Determines whether this function should propagate to the LeftChild and RightChild properties by setting the property to leftChild. Only set this to false if the new children are already set in the node before calling this function.

SetChildren(TTreeNode, TTreeNode, TTreeNode, bool)

Sets the children of a node within this tree.

public void SetChildren(TTreeNode node, TTreeNode leftChild, TTreeNode rightChild, bool propagate = true)

Parameters

node TTreeNode

The parent node whose children to set. The node must be within this tree.

leftChild TTreeNode

The left child to set to the node.

rightChild TTreeNode

The right child to set to the node.

propagate bool

Determines whether this function should propagate to the LeftChild and RightChild properties by setting the property to leftChild and rightChild respectively. Only set this to false if the new children are already set in the node before calling this function.

TraverseInOrder()

Traverses the tree from the root using pre-order. The elements are returned with yield return.

public IEnumerable<TValue> TraverseInOrder()

Returns

IEnumerable<TValue>

The yielded values.

TraverseInOrderNodes()

Traverses the tree from the root using pre-order. The nodes are returned with yield return.

public IEnumerable<TTreeNode> TraverseInOrderNodes()

Returns

IEnumerable<TTreeNode>

The yielded nodes.