Table of Contents

Class BinarySearchTreeNode<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 BinarySearchTreeNode<TValue, TTree, TTreeNode> : BinaryTreeNode<TValue, TTree, TTreeNode>, ITreeNode<TValue, TTree, TTreeNode>, ITreeNode<TValue>, IEnumerable<TValue>, IEnumerable where TValue : IComparable<TValue> where TTree : BinarySearchTree<TValue, TTree, TTreeNode> where TTreeNode : BinarySearchTreeNode<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>
BinaryTreeNode<TValue, TTree, TTreeNode>
BinarySearchTreeNode<TValue, TTree, TTreeNode>
Implements
ITreeNode<TValue, TTree, TTreeNode>
ITreeNode<TValue>
IEnumerable<TValue>
Derived
Inherited Members
Extension Methods

Constructors

BinarySearchTreeNode(TValue)

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

public BinarySearchTreeNode(TValue value = default)

Parameters

value TValue

The value of the node.

BinarySearchTreeNode(TTree, TValue)

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

public BinarySearchTreeNode(TTree baseTree, TValue value = default)

Parameters

baseTree TTree

The base tree that contains this node.

value TValue

The value of the node.

BinarySearchTreeNode(TTreeNode, TValue)

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

public BinarySearchTreeNode(TTreeNode parentNode, TValue value = default)

Parameters

parentNode TTreeNode

The parent node.

value TValue

The value of the node.

BinarySearchTreeNode(TTreeNode, TTreeNode, TTreeNode, TValue)

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

public BinarySearchTreeNode(TTreeNode parentNode, TTreeNode child1, TTreeNode child2, TValue value = default)

Parameters

parentNode TTreeNode

The parent node.

child1 TTreeNode

The first child node.

child2 TTreeNode

The second child node.

value TValue

The value of the node.

Properties

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 { 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.

Parent

Gets or sets the parent node of this tree node.

public override TTreeNode Parent { set; }

Property Value

TTreeNode

Methods

AddChild(TTreeNode)

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

public override void AddChild(TTreeNode newChild)

Parameters

newChild TTreeNode

The new 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 override 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.

AddNode(TValue)

Adds a new node to this subtree.

public bool AddNode(TValue value)

Parameters

value TValue

The value of the node to add to this subtree.

Returns

bool

true if the node was successsfully added to this subtree, otherwise false.

AddNode(TTreeNode)

Adds a new node to this subtree.

public bool AddNode(TTreeNode node)

Parameters

node TTreeNode

The node to add to this subtree.

Returns

bool

true if the node was successsfully added to this subtree, otherwise false.

AddNodes(IEnumerable<TValue>)

Adds a collection of nodes to this subtree.

public void AddNodes(IEnumerable<TValue> values)

Parameters

values IEnumerable<TValue>

The values of the nodes to add to this subtree.

AddNodes(IEnumerable<TTreeNode>)

Adds a collection of nodes to this subtree.

public void AddNodes(IEnumerable<TTreeNode> nodes)

Parameters

nodes IEnumerable<TTreeNode>

The the nodes to add to this subtree.

AddNodes(params TValue[])

Adds a collection of nodes to this subtree.

public void AddNodes(params TValue[] values)

Parameters

values TValue[]

The values of the nodes to add to this subtree.

AddNodes(params TTreeNode[])

Adds a collection of nodes to this subtree.

public void AddNodes(params TTreeNode[] nodes)

Parameters

nodes TTreeNode[]

The the nodes to add to this subtree.

Find(TValue)

Attempts to find a node with the specified value within this subtree.

public TTreeNode Find(TValue value)

Parameters

value TValue

The value of the node to be found.

Returns

TTreeNode

The node within this subtree that has the specified value, if found, otherwise null.

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

RemoveNode(TValue)

Removes a node with the specified value from this subtree.

public override bool RemoveNode(TValue value)

Parameters

value TValue

The value of the node to remove from this subtree.

Returns

bool

true if the node was successfully removed from this subtree, otherwise false.