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
TValueThe type of the value that is stored in the node.
TTreeThe type of the tree that this type is used in.
TTreeNodeThe type of the tree nodes that are used in the
TTreetype.
- 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
valueTValueThe 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
baseTreeTTreeThe base tree that contains this node.
valueTValueThe 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
parentNodeTTreeNodeThe parent node.
valueTValueThe 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
parentNodeTTreeNodeThe parent node.
child1TTreeNodeThe first child node.
child2TTreeNodeThe second child node.
valueTValueThe 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
newChildTTreeNodeThe 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
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.
AddNode(TValue)
Adds a new node to this subtree.
public bool AddNode(TValue value)
Parameters
valueTValueThe value of the node to add to this subtree.
Returns
AddNode(TTreeNode)
Adds a new node to this subtree.
public bool AddNode(TTreeNode node)
Parameters
nodeTTreeNodeThe node to add to this subtree.
Returns
AddNodes(IEnumerable<TValue>)
Adds a collection of nodes to this subtree.
public void AddNodes(IEnumerable<TValue> values)
Parameters
valuesIEnumerable<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
nodesIEnumerable<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
valuesTValue[]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
nodesTTreeNode[]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
valueTValueThe 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
valueTValueThe 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
valueTValueThe value of the node to remove from this subtree.