Class BinaryTree<TData>
Standard implementation of a binary tree.
Inheritance
Inherited Members
Namespace: Telerik.Windows.Diagrams.Core
Assembly: Telerik.Windows.Diagrams.Core.dll
Syntax
public class BinaryTree<TData> : ICollection<TData>, IEnumerable<TData>, IEnumerable, ITree<TData>
Type Parameters
TData
The data type on which the tree is based. |
Constructors
BinaryTree(TData, TData, TData)
Initializes a new instance of the BinaryTree<TData> class.
Declaration
public BinaryTree(TData data, TData left, TData right)
Parameters
TData
data
The data. |
TData
left
The left. |
TData
right
The right. |
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
TData
data
The data. |
BinaryTree<TData>
left
The left. |
BinaryTree<TData>
right
The right. |
Properties
Count
Gets the number of children at this level, which can be at most two.
Declaration
public int Count { get; }
Property Value
System.Int32
|
Implements
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.
Declaration
public int Degree { get; }
Property Value
System.Int32
|
Implements
Height
Gets the height.
Declaration
public virtual int Height { get; }
Property Value
System.Int32
|
Implements
IsComplete
Gets whether both sides are occupied, i.e. the left and right positions are filled.
Declaration
public bool IsComplete { get; }
Property Value
System.Boolean
|
IsEmpty
Gets a value indicating whether this tree is empty.
Declaration
public bool IsEmpty { get; }
Property Value
System.Boolean
|
IsLeafNode
Gets whether this is a leaf node, i.e. it doesn't have children nodes.
Declaration
public virtual bool IsLeafNode { get; }
Property Value
System.Boolean
|
Implements
IsReadOnly
Returns false
; this tree is never read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
System.Boolean
|
Implements
Item[Int32]
Gets the BinaryTree<TData> at the specified index.
Declaration
public BinaryTree<TData> this[int index] { get; }
Parameters
System.Int32
index
|
Property Value
BinaryTree<TData>
|
Left
Gets or sets the left subtree.
Declaration
public virtual BinaryTree<TData> Left { get; set; }
Property Value
BinaryTree<TData>
The left subtree. |
Parent
Gets the parent of the current node.
Declaration
public BinaryTree<TData> Parent { get; set; }
Property Value
BinaryTree<TData>
The parent of the current node. |
Right
Gets or sets the right subtree.
Declaration
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>
|
Methods
Add(TData)
Adds the given item to this tree.
Declaration
public virtual void Add(TData item)
Parameters
TData
item
The item to add. |
Implements
Add(BinaryTree<TData>)
Adds an item to the System.Collections.Generic.ICollection<T>.
Declaration
public void Add(BinaryTree<TData> subtree)
Parameters
BinaryTree<TData>
subtree
The subtree. |
Exceptions
System.NotSupportedException
The System.Collections.Generic.ICollection<T> is read-only. |
System.InvalidOperationException
The BinaryTree<TData> is full. |
System.ArgumentNullException
|
BreadthFirstTraversal(IVisitor<TData>)
Performs a breadth first traversal on this tree with the specified visitor.
Declaration
public virtual void BreadthFirstTraversal(IVisitor<TData> visitor)
Parameters
IVisitor<TData>
visitor
The visitor. |
Exceptions
System.ArgumentNullException
|
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
TData
item
The item. |
Returns
System.Boolean
|
Implements
CopyTo(TData[], Int32)
Copies the tree to the given array.
Declaration
public void CopyTo(TData[] array, int arrayIndex)
Parameters
TData[]
array
The array. |
System.Int32
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
IVisitor<TData>
visitor
The ordered visitor. |
Exceptions
System.ArgumentNullException
|
Find(TData)
Seeks the tree node containing the given data.
Declaration
public BinaryTree<TData> Find(TData value)
Parameters
TData
value
The value. |
Returns
BinaryTree<TData>
|
FindMaximumChildHeight()
Finds the maximum height between the child nodes.
Declaration
protected virtual int FindMaximumChildHeight()
Returns
System.Int32
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
System.Predicate<TData>
condition
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
System.ArgumentNullException
|
GetChild(Int32)
Gets the left (index zero) or right (index one) subtree.
Declaration
public BinaryTree<TData> GetChild(int index)
Parameters
System.Int32
index
The index of the child in question. |
Returns
BinaryTree<TData>
The child at the specified index. |
Exceptions
System.ArgumentOutOfRangeException
|
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<TData> GetEnumerator()
Returns
System.Collections.Generic.IEnumerator<TData>
A System.Collections.Generic.IEnumerator<T> that can be used to iterate through the collection. |
Implements
Remove(TData)
Removes the specified item from the tree.
Declaration
public virtual bool Remove(TData item)
Parameters
TData
item
The item to remove. |
Returns
System.Boolean
|
Implements
Remove(BinaryTree<TData>)
Removes the specified child.
Declaration
public virtual bool Remove(BinaryTree<TData> child)
Parameters
BinaryTree<TData>
child
The child. |
Returns
System.Boolean
Returns whether the child was found (and removed) from this tree. |
RemoveLeft()
Removes the left child.
Declaration
public virtual void RemoveLeft()
RemoveRight()
Removes the left child.
Declaration
public virtual void RemoveRight()
ToString()
Returns a System.String that represents this instance.
Declaration
public override string ToString()
Returns
System.String
A System.String that represents this instance. |
Overrides
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Returns an enumerator that iterates through a collection.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
System.Collections.IEnumerator
An System.Collections.IEnumerator object that can be used to iterate through the collection. |
Implements
ITree<TData>.Add(ITree<TData>)
ITree<TData>.FindNode(Predicate<TData>)
Declaration
ITree<TData> ITree<TData>.FindNode(Predicate<TData> condition)
Parameters
System.Predicate<TData>
condition
|
Returns
ITree<TData>
|
Implements
ITree<TData>.GetChild(Int32)
Declaration
ITree<TData> ITree<TData>.GetChild(int index)
Parameters
System.Int32
index
|
Returns
ITree<TData>
|
Implements
ITree<TData>.Parent
Gets the parent.
Declaration
ITree<TData> ITree<TData>.Parent { get; }
Returns
ITree<TData>
|
Implements
ITree<TData>.Remove(ITree<TData>)
Removes the specified child.
Declaration
bool ITree<TData>.Remove(ITree<TData> child)
Parameters
ITree<TData>
child
The child. |
Returns
System.Boolean
|