New to Telerik UI for WPFStart a free 30-day trial

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:

C#
public class BinaryTree<TData> : ICollection<TData>, IEnumerable<TData>, IEnumerable, ITree<TData>

Inheritance: objectBinaryTree<TData>

Implements: ICollection<TData>IEnumerableIEnumerable<TData>ITree<TData>

Constructors

Initializes a new instance of the BinaryTree<TData> class.

C#
public BinaryTree(TData data, BinaryTree<TData> left = null, BinaryTree<TData> right = null)
Parameters:dataTData

The data.

leftBinaryTree<TData>

The left.

rightBinaryTree<TData>

The right.

Initializes a new instance of the BinaryTree<TData> class.

C#
public BinaryTree(TData data, TData left, TData right)
Parameters:dataTData

The data.

leftTData

The left.

rightTData

The right.

Properties

Gets the number of children at this level, which can be at most two.

C#
public int Count { get; }

Implements: ICollection<TData>.Count

Data

TData

Gets or sets the data of this tree.

C#
public TData Data { get; set; }
Property Value:

The data.

Implements: ITree<TData>.Data

Gets the degree.

C#
public int Degree { get; }

Implements: ITree<TData>.Degree

Gets the height.

C#
public virtual int Height { get; }

Implements: ITree<TData>.Height

Gets whether both sides are occupied, i.e. the left and right positions are filled.

C#
public bool IsComplete { get; }
Property Value:

true if this instance is full; otherwise, false.

Gets a value indicating whether this tree is empty.

C#
public bool IsEmpty { get; }
Property Value:

true if this instance is empty; otherwise, false.

Gets whether this is a leaf node, i.e. it doesn't have children nodes.

C#
public virtual bool IsLeafNode { get; }
Property Value:

true if this instance is leaf node; otherwise, false.

Implements: ITree<TData>.IsLeafNode

Returns false; this tree is never read-only.

C#
public bool IsReadOnly { get; }
Property Value:

true if this instance is read only; otherwise, false.

Implements: ICollection<TData>.IsReadOnly

Gets or sets the left subtree.

C#
public virtual BinaryTree<TData> Left { get; set; }
Property Value:

The left subtree.

Gets the parent of the current node.

C#
public BinaryTree<TData> Parent { get; set; }
Property Value:

The parent of the current node.

Gets or sets the right subtree.

C#
public virtual BinaryTree<TData> Right { get; set; }
Property Value:

The right subtree.

Gets the root of the binary tree.

C#
public BinaryTree<TData> Root { get; }

Gets the BinaryTree<TData> at the specified index.

C#
public BinaryTree<TData> this[int index] { get; }
Parameters:indexint

Methods

Adds an item to the ICollection<T>.

C#
public void Add(BinaryTree<TData> subtree)
Parameters:subtreeBinaryTree<TData>

The subtree.

Exceptions:

NotSupportedException

The ICollection<T> is read-only.

InvalidOperationException

The BinaryTree<TData> is full.

ArgumentNullException

subtree is null (Nothing in Visual Basic).

Adds the given item to this tree.

C#
public virtual void Add(TData item)
Parameters:itemTData

The item to add.

Implements: ICollection<TData>.Add(TData)

Performs a breadth first traversal on this tree with the specified visitor.

C#
public virtual void BreadthFirstTraversal(IVisitor<TData> visitor)
Parameters:visitorIVisitor<TData>

The visitor.

Exceptions:

ArgumentNullException

visitor is a null reference (Nothing in Visual Basic).

Clears this tree of its content.

C#
public virtual void Clear()

Implements: ICollection<TData>.Clear()

Returns whether the given item is contained in this collection.

C#
public bool Contains(TData item)
Parameters:itemTData

The item.

Returns:

bool

true if is contained in this collection; otherwise, false.

Implements: ICollection<TData>.Contains(TData)

Copies the tree to the given array.

C#
public void CopyTo(TData[] array, int arrayIndex)
Parameters:arrayTData[]

The array.

arrayIndexint

Index of the array.

Implements: ICollection<TData>.CopyTo(TData[], int)

Performs a depth first traversal on this tree with the specified visitor.

C#
public virtual void DepthFirstTraversal(IVisitor<TData> visitor)
Parameters:visitorIVisitor<TData>

The ordered visitor.

Exceptions:

ArgumentNullException

visitor is a null reference (Nothing in Visual Basic).

Seeks the tree node containing the given data.

C#
public BinaryTree<TData> Find(TData value)
Parameters:valueTData

The value.

Returns:

BinaryTree<TData>

Finds the maximum height between the child nodes.

C#
protected virtual int FindMaximumChildHeight()
Returns:

int

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.

C#
public BinaryTree<TData> FindNode(Predicate<TData> condition)
Parameters:conditionPredicate<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:

ArgumentNullException

condition is a null reference (Nothing in Visual Basic).

Gets the left (index zero) or right (index one) subtree.

C#
public BinaryTree<TData> GetChild(int index)
Parameters:indexint

The index of the child in question.

Returns:

BinaryTree<TData>

The child at the specified index.

Exceptions:

ArgumentOutOfRangeException

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.

C#
public IEnumerator<TData> GetEnumerator()
Returns:

IEnumerator<TData>

A IEnumerator<T> that can be used to iterate through the collection.

Implements: IEnumerable<TData>.GetEnumerator()

Removes the specified child.

C#
public virtual bool Remove(BinaryTree<TData> child)
Parameters:childBinaryTree<TData>

The child.

Returns:

bool

Returns whether the child was found (and removed) from this tree.

Removes the specified item from the tree.

C#
public virtual bool Remove(TData item)
Parameters:itemTData

The item to remove.

Returns:

bool

Implements: ICollection<TData>.Remove(TData)

Removes the left child.

C#
public virtual void RemoveLeft()

Removes the left child.

C#
public virtual void RemoveRight()

Returns a string that represents this instance.

C#
public override string ToString()
Returns:

string

A string that represents this instance.

Overrides: object.ToString()