Class BinaryTree<TNode>
Base class for binary trees. This class does not implement a binary search tree, but can used to implement one. For binary search trees, please refer to RedBlackTree<T>, KDTree and VPTree.
Namespace: ISynergy.Framework.Core.Collections
Assembly: ISynergy.Framework.Core.dll
Syntax
public class BinaryTree<TNode> : IEnumerable<TNode> where TNode : BinaryNode<TNode>
Type Parameters
Name | Description |
---|---|
TNode | The class type for the nodes of the tree. |
Examples
The BinaryTree<TNode> class is a base class for other tree classes such as RedBlackTree<T>, KDTree and VPTree. For examples on how to use those classes, please see their respective documentation pages.
If you would like to implement your own binary tree that inherits from this class, then you can do so as shown in the following example. First, make sure your custom node class inherits from BinaryNode<TNode> and passes itself as the generic argument of BinaryNode<TNode>:
Now, once the tree node has been implemented, we can create a new BinaryTree<TNode> and explore the tree in different ways as shown below:
Properties
View SourceRoot
Gets the root node of this tree.
Declaration
public TNode Root { get; set; }
Property Value
Type | Description |
---|---|
TNode |
Methods
View SourceGetEnumerator()
Returns an enumerator that iterates through the tree.
Declaration
public virtual IEnumerator<TNode> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<TNode> | An IEnumerator object that can be used to iterate through the collection. |
Traverse(BinaryTraversalMethod<TNode>)
Traverse the tree using a tree traversal method. Can be iterated with a foreach loop.
Declaration
public IEnumerable<TNode> Traverse(BinaryTraversalMethod<TNode> method)
Parameters
Type | Name | Description |
---|---|---|
BinaryTraversalMethod<TNode> | method | The tree traversal method. Common methods are available in the TreeTraversalstatic class. |
Returns
Type | Description |
---|---|
IEnumerable<TNode> | An |