Class BinaryTree<TData>
Standard implementation of a binary tree.
Inheritance
Namespace: Telerik.Windows.Diagrams.Core
Assembly: Telerik.Windows.Diagrams.Core.dll
Syntax
public class BinaryTree<TData> : Object, 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. |
Binary The left. |
Binary 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.
|
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.
|
Implements
Height
Gets the height.
Declaration
public virtual int Height { get; }
Property Value
System.
|
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.
|
IsEmpty
Gets a value indicating whether this tree is empty.
Declaration
public bool IsEmpty { get; }
Property Value
System.
|
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.
|
Implements
IsReadOnly
Returns false
; this tree is never read-only.
Declaration
public bool IsReadOnly { get; }
Property Value
System.
|
Item[Int32]
Gets the BinaryTree<TData> at the specified index.
Declaration
public BinaryTree<TData> this[int index] { get; }
Parameters
System.
|
Property Value
Binary
|
Left
Gets or sets the left subtree.
Declaration
public virtual BinaryTree<TData> Left { get; set; }
Property Value
Binary The left subtree. |
Parent
Gets the parent of the current node.
Declaration
public BinaryTree<TData> Parent { get; set; }
Property Value
Binary The parent of the current node. |
Right
Gets or sets the right subtree.
Declaration
public virtual BinaryTree<TData> Right { get; set; }
Property Value
Binary The right subtree. |
Root
Gets the root of the binary tree.
Declaration
public BinaryTree<TData> Root { get; }
Property Value
Binary
|
Methods
Add(TData)
Adds the given item to this tree.
Declaration
public virtual void Add(TData item)
Parameters
TData
item
The item to add. |
Add(BinaryTree<TData>)
Adds an item to the System.Collections.Generic.ICollection<>.
Declaration
public void Add(BinaryTree<TData> subtree)
Parameters
Binary The subtree. |
Exceptions
System. The System.Collections.Generic.ICollection<> is read-only. |
System. The BinaryTree<TData> is full. |
System.
|
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.
|
Clear()
Clears this tree of its content.
Declaration
public virtual void Clear()
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.
|
CopyTo(TData[], Int32)
Copies the tree to the given array.
Declaration
public void CopyTo(TData[] array, int arrayIndex)
Parameters
TData[]
array
The array. |
System. Index of the array. |
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.
|
Find(TData)
Seeks the tree node containing the given data.
Declaration
public BinaryTree<TData> Find(TData value)
Parameters
TData
value
The value. |
Returns
Binary
|
FindMaximumChildHeight()
Finds the maximum height between the child nodes.
Declaration
protected virtual int FindMaximumChildHeight()
Returns
System. 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. The condition to test. |
Returns
Binary The first node that matches the condition supplied. If a node is not found, null is returned. |
Exceptions
System.
|
GetChild(Int32)
Gets the left (index zero) or right (index one) subtree.
Declaration
public BinaryTree<TData> GetChild(int index)
Parameters
System. The index of the child in question. |
Returns
Binary The child at the specified index. |
Exceptions
System.
|
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public IEnumerator<TData> GetEnumerator()
Returns
System. A System.Collections.Generic.IEnumerator<> that can be used to iterate through the collection. |
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.
|
Remove(BinaryTree<TData>)
Removes the specified child.
Declaration
public virtual bool Remove(BinaryTree<TData> child)
Parameters
Binary The child. |
Returns
System. 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.
Declaration
public override string ToString()
Returns
System. A System. |
Explicit Interface Implementations
ITree<TData>.Add(ITree<TData>)
ITree<TData>.FindNode(Predicate<TData>)
Declaration
ITree<TData> ITree<TData>.FindNode(Predicate<TData> condition)
Parameters
System.
|
Returns
ITree<TData>
|
Implements
ITree<TData>.GetChild(Int32)
Declaration
ITree<TData> ITree<TData>.GetChild(int index)
Parameters
System.
|
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.
|