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
TValueThe type of the value that is stored in the node.
TTreeThe type of the binary tree that this type is used in.
TTreeNodeThe type of the binary tree nodes that are used in the
TTreetype.
- 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
valueTValueThe 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
baseTreeTTreeThe base tree that contains this node.
valueTValueThe 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
parentNodeTTreeNodeThe parent node.
valueTValueThe 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
parentNodeTTreeNodeThe parent node.
leftChildTTreeNodeThe left child node.
rightChildTTreeNodeThe right child node.
valueTValueThe 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
Height
Gets the height of this tree node's subtree.
public override sealed int Height { get; }
Property Value
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
valueTValueThe 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
newChildTTreeNodeThe 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
leftTValueThe value of the left child to add.
rightTValueThe 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
leftTTreeNodeThe left child to add.
rightTTreeNodeThe 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
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 the leftmost 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 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
childToRemoveTTreeNodeThe child to remove from the children collection.
Returns
RegisterAddedChild(TTreeNode)
Performs the operations after a child was added to this tree.
protected override sealed 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.
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.