BinaryTree<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:
public class BinaryTree<TData> : ICollection<TData>, IEnumerable<TData>, IEnumerable, ITree<TData>
Inheritance: objectBinaryTree<TData>
Implements:
Constructors
Initializes a new instance of the BinaryTree<TData> class.
public BinaryTree(TData data, BinaryTree<TData> left = null, BinaryTree<TData> right = null)
The data.
leftBinaryTree<TData>The left.
rightBinaryTree<TData>The right.
Initializes a new instance of the BinaryTree<TData> class.
public BinaryTree(TData data, TData left, TData right)
The data.
leftTDataThe left.
rightTDataThe right.
Properties
Gets the number of children at this level, which can be at most two.
public int Count { get; }
Implements:
Data
TData
Gets or sets the data of this tree.
public TData Data { get; set; }
The data.
Implements:
Gets whether both sides are occupied, i.e. the left and right positions are filled.
public bool IsComplete { get; }
true if this instance is full; otherwise, false.
Gets a value indicating whether this tree is empty.
public bool IsEmpty { get; }
true if this instance is empty; otherwise, false.
Gets whether this is a leaf node, i.e. it doesn't have children nodes.
public virtual bool IsLeafNode { get; }
true if this instance is leaf node; otherwise, false.
Implements:
Returns false; this tree is never read-only.
public bool IsReadOnly { get; }
true if this instance is read only; otherwise, false.
Implements:
Left
BinaryTree<TData>
Gets or sets the left subtree.
public virtual BinaryTree<TData> Left { get; set; }
The left subtree.
Parent
BinaryTree<TData>
Gets the parent of the current node.
public BinaryTree<TData> Parent { get; set; }
The parent of the current node.
Right
BinaryTree<TData>
Gets or sets the right subtree.
public virtual BinaryTree<TData> Right { get; set; }
The right subtree.
Root
BinaryTree<TData>
Gets the root of the binary tree.
public BinaryTree<TData> Root { get; }
this[int]
BinaryTree<TData>
Gets the BinaryTree<TData> at the specified index.
Methods
Adds an item to the ICollection<T>.
public void Add(BinaryTree<TData> subtree)
The subtree.
Exceptions:The ICollection<T> is read-only.
The BinaryTree<TData> is full.
subtree is null (Nothing in Visual Basic).
Adds the given item to this tree.
public virtual void Add(TData item)
The item to add.
Implements:
Performs a breadth first traversal on this tree with the specified visitor.
public virtual void BreadthFirstTraversal(IVisitor<TData> visitor)
The visitor.
Exceptions:visitor is a null reference (Nothing in Visual Basic).
Clears this tree of its content.
public virtual void Clear()
Implements:
Returns whether the given item is contained in this collection.
public bool Contains(TData item)
The item.
Returns:true if is contained in this collection; otherwise, false.
Implements:
Copies the tree to the given array.
public void CopyTo(TData[] array, int arrayIndex)
The array.
arrayIndexintIndex of the array.
Implements:
Performs a depth first traversal on this tree with the specified visitor.
public virtual void DepthFirstTraversal(IVisitor<TData> visitor)
The ordered visitor.
Exceptions:visitor is a null reference (Nothing in Visual Basic).
Seeks the tree node containing the given data.
public BinaryTree<TData> Find(TData value)
The value.
Returns:BinaryTree<TData>
Finds the maximum height between the child nodes.
protected virtual int FindMaximumChildHeight()
The maximum height of the tree between all paths from this node and all leaf nodes.
Finds the node with the specified condition. If a node is not found matching the specified condition, null is returned.
public BinaryTree<TData> FindNode(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:condition is a null reference (Nothing in Visual Basic).
Gets the left (index zero) or right (index one) subtree.
public BinaryTree<TData> GetChild(int 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.
Returns an enumerator that iterates through the collection.
public IEnumerator<TData> GetEnumerator()
IEnumerator<TData>
A IEnumerator<T> that can be used to iterate through the collection.
Implements:
Removes the specified child.
public virtual bool Remove(BinaryTree<TData> child)
The child.
Returns:Returns whether the child was found (and removed) from this tree.
Removes the specified item from the tree.
public virtual bool Remove(TData item)
The item to remove.
Returns:Implements:
Removes the left child.
public virtual void RemoveLeft()
Removes the left child.
public virtual void RemoveRight()