ClassBinaryTree<TData>
Standard implementation of a binary tree.
Definition
Namespace:Telerik.Windows.Diagrams.Core
Assembly:Telerik.Windows.Diagrams.Core.dll
Type Parameters:
TData
The data type on which the tree is based.
Syntax:
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
public class BinaryTree<TData> : ICollection<TData>, IEnumerable<TData>, IEnumerable, ITree<TData>
Inheritance: objectBinaryTree<TData>
Implements:
Constructors
BinaryTree(TData, BinaryTree<TData>, BinaryTree<TData>)
Initializes a new instance of the BinaryTree<TData> class.
Declaration
public BinaryTree(TData data, BinaryTree<TData> left = null, BinaryTree<TData> right = null)
Parameters
data
TData
The data.
left
BinaryTree<TData>
The left.
right
BinaryTree<TData>
The right.
BinaryTree(TData, TData, TData)
Initializes a new instance of the BinaryTree<TData> class.
Declaration
public BinaryTree(TData data, TData left, TData right)
Parameters
data
TData
The data.
left
TData
The left.
right
TData
The right.
Properties
Count
Gets the number of children at this level, which can be at most two.
Data
Gets or sets the data of this tree.
Declaration
public TData Data { get; set; }
Property Value
TData
The data.
Implements
Degree
Gets the degree.
Height
Gets the height.
IsComplete
Gets whether both sides are occupied, i.e. the left and right positions are filled.
Declaration
public bool IsComplete { get; }
Property Value
true if this instance is full; otherwise, false.
IsEmpty
Gets a value indicating whether this tree is empty.
Declaration
public bool IsEmpty { get; }
Property Value
true if this instance is empty; otherwise, false.
IsLeafNode
Gets whether this is a leaf node, i.e. it doesn't have children nodes.
Declaration
public virtual bool IsLeafNode { get; }
Property Value
true if this instance is leaf node; otherwise, false.
Implements
IsReadOnly
Returns false; this tree is never read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
true if this instance is read only; otherwise, false.
Implements
Left
Gets or sets the left subtree.
Declaration
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual BinaryTree<TData> Left { get; set; }
Property Value
BinaryTree<TData>
The left subtree.
Parent
Gets the parent of the current node.
Declaration
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public BinaryTree<TData> Parent { get; set; }
Property Value
BinaryTree<TData>
The parent of the current node.
Right
Gets or sets the right subtree.
Declaration
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual BinaryTree<TData> Right { get; set; }
Property Value
BinaryTree<TData>
The right subtree.
Root
Gets the root of the binary tree.
Declaration
public BinaryTree<TData> Root { get; }
Property Value
BinaryTree<TData>
this[int]
Gets the BinaryTree<TData> at the specified index.
Declaration
public BinaryTree<TData> this[int index] { get; }
Parameters
index
Property Value
BinaryTree<TData>
Methods
Add(BinaryTree<TData>)
Adds an item to the ICollection<T>.
Declaration
public void Add(BinaryTree<TData> subtree)
Parameters
subtree
BinaryTree<TData>
The subtree.
Exceptions
The ICollection<T> is read-only.
The BinaryTree<TData> is full.
subtree is null (Nothing in Visual Basic).
Add(TData)
Adds the given item to this tree.
Declaration
public virtual void Add(TData item)
Parameters
item
TData
The item to add.
Implements
BreadthFirstTraversal(IVisitor<TData>)
Performs a breadth first traversal on this tree with the specified visitor.
Declaration
public virtual void BreadthFirstTraversal(IVisitor<TData> visitor)
Parameters
visitor
IVisitor<TData>
The visitor.
Exceptions
visitor is a null reference (Nothing in Visual Basic).
Clear()
Clears this tree of its content.
Declaration
public virtual void Clear()
Implements
Contains(TData)
Returns whether the given item is contained in this collection.
Declaration
public bool Contains(TData item)
Parameters
item
TData
The item.
Returns
true if is contained in this collection; otherwise, false.
Implements
CopyTo(TData[], int)
Copies the tree to the given array.
Declaration
public void CopyTo(TData[] array, int arrayIndex)
Parameters
array
TData[]
The array.
arrayIndex
Index of the array.
Implements
DepthFirstTraversal(IVisitor<TData>)
Performs a depth first traversal on this tree with the specified visitor.
Declaration
public virtual void DepthFirstTraversal(IVisitor<TData> visitor)
Parameters
visitor
IVisitor<TData>
The ordered visitor.
Exceptions
visitor is a null reference (Nothing in Visual Basic).
Find(TData)
Seeks the tree node containing the given data.
Declaration
public BinaryTree<TData> Find(TData value)
Parameters
value
TData
The value.
Returns
BinaryTree<TData>
FindMaximumChildHeight()
Finds the maximum height between the child nodes.
Declaration
protected virtual int FindMaximumChildHeight()
Returns
The maximum height of the tree between all paths from this node and all leaf nodes.
FindNode(Predicate<TData>)
Finds the node with the specified condition. If a node is not found matching the specified condition, null is returned.
Declaration
public BinaryTree<TData> FindNode(Predicate<TData> condition)
Parameters
condition
Predicate<TData>
The condition to test.
Returns
BinaryTree<TData>
The first node that matches the condition supplied. If a node is not found, null is returned.
Exceptions
condition is a null reference (Nothing in Visual Basic).
GetChild(int)
Gets the left (index zero) or right (index one) subtree.
Declaration
public BinaryTree<TData> GetChild(int index)
Parameters
index
The index of the child in question.
Returns
BinaryTree<TData>
The child at the specified index.
Exceptions
indexThere are at most two children at each level of a binary tree, the index can hence only be zero or one.
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<TData> GetEnumerator()
Returns
IEnumerator<TData>
A IEnumerator<T> that can be used to iterate through the collection.
Implements
Remove(BinaryTree<TData>)
Removes the specified child.
Declaration
public virtual bool Remove(BinaryTree<TData> child)
Parameters
child
BinaryTree<TData>
The child.
Returns
Returns whether the child was found (and removed) from this tree.
Remove(TData)
Removes the specified item from the tree.
Declaration
public virtual bool Remove(TData item)
Parameters
item
TData
The item to remove.
Returns
Implements
ToString()
Returns a string that represents this instance.