Class
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:

cs-api-definition
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
public class BinaryTree<TData> : ICollection<TData>, IEnumerable<TData>, IEnumerable, ITree<TData>

Inheritance: objectBinaryTree<TData>

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

Constructors

BinaryTree(TData, BinaryTree<TData>, BinaryTree<TData>)

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

Declaration

cs-api-definition
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

cs-api-definition
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.

Declaration

cs-api-definition
public int Count { get; }

Property Value

int

Implements ICollection<TData>.Count

Data

Gets or sets the data of this tree.

Declaration

cs-api-definition
public TData Data { get; set; }

Property Value

TData

The data.

Implements ITree<TData>.Data

Degree

Gets the degree.

Declaration

cs-api-definition
public int Degree { get; }

Property Value

int

Implements ITree<TData>.Degree

Height

Gets the height.

Declaration

cs-api-definition
public virtual int Height { get; }

Property Value

int

Implements ITree<TData>.Height

IsComplete

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

Declaration

cs-api-definition
public bool IsComplete { get; }

Property Value

bool

true if this instance is full; otherwise, false.

IsEmpty

Gets a value indicating whether this tree is empty.

Declaration

cs-api-definition
public bool IsEmpty { get; }

Property Value

bool

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

cs-api-definition
public virtual bool IsLeafNode { get; }

Property Value

bool

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

Implements ITree<TData>.IsLeafNode

IsReadOnly

Returns false; this tree is never read-only.

Declaration

cs-api-definition
public bool IsReadOnly { get; }

Property Value

bool

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

Implements ICollection<TData>.IsReadOnly

Left

Gets or sets the left subtree.

Declaration

cs-api-definition
[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

cs-api-definition
[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

cs-api-definition
[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

cs-api-definition
public BinaryTree<TData> Root { get; }

Property Value

BinaryTree<TData>

this[int]

Gets the BinaryTree<TData> at the specified index.

Declaration

cs-api-definition
public BinaryTree<TData> this[int index] { get; }

Parameters

index

int

Property Value

BinaryTree<TData>

Methods

Add(BinaryTree<TData>)

Adds an item to the ICollection<T>.

Declaration

cs-api-definition
public void Add(BinaryTree<TData> subtree)

Parameters

subtree

BinaryTree<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).

Add(TData)

Adds the given item to this tree.

Declaration

cs-api-definition
public virtual void Add(TData item)

Parameters

item

TData

The item to add.

Implements ICollection<TData>.Add(TData)

BreadthFirstTraversal(IVisitor<TData>)

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

Declaration

cs-api-definition
public virtual void BreadthFirstTraversal(IVisitor<TData> visitor)

Parameters

visitor

IVisitor<TData>

The visitor.

Exceptions

ArgumentNullException

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

Clear()

Clears this tree of its content.

Declaration

cs-api-definition
public virtual void Clear()

Implements ICollection<TData>.Clear()

Contains(TData)

Returns whether the given item is contained in this collection.

Declaration

cs-api-definition
public bool Contains(TData item)

Parameters

item

TData

The item.

Returns

bool

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

Implements ICollection<TData>.Contains(TData)

CopyTo(TData[], int)

Copies the tree to the given array.

Declaration

cs-api-definition
public void CopyTo(TData[] array, int arrayIndex)

Parameters

array

TData[]

The array.

arrayIndex

int

Index of the array.

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

DepthFirstTraversal(IVisitor<TData>)

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

Declaration

cs-api-definition
public virtual void DepthFirstTraversal(IVisitor<TData> visitor)

Parameters

visitor

IVisitor<TData>

The ordered visitor.

Exceptions

ArgumentNullException

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

Find(TData)

Seeks the tree node containing the given data.

Declaration

cs-api-definition
public BinaryTree<TData> Find(TData value)

Parameters

value

TData

The value.

Returns

BinaryTree<TData>

FindMaximumChildHeight()

Finds the maximum height between the child nodes.

Declaration

cs-api-definition
protected virtual int FindMaximumChildHeight()

Returns

int

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

cs-api-definition
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

ArgumentNullException

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

GetChild(int)

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

Declaration

cs-api-definition
public BinaryTree<TData> GetChild(int index)

Parameters

index

int

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.

GetEnumerator()

Returns an enumerator that iterates through the collection.

Declaration

cs-api-definition
public IEnumerator<TData> GetEnumerator()

Returns

IEnumerator<TData>

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

Implements IEnumerable<TData>.GetEnumerator()

Remove(BinaryTree<TData>)

Removes the specified child.

Declaration

cs-api-definition
public virtual bool Remove(BinaryTree<TData> child)

Parameters

child

BinaryTree<TData>

The child.

Returns

bool

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

Remove(TData)

Removes the specified item from the tree.

Declaration

cs-api-definition
public virtual bool Remove(TData item)

Parameters

item

TData

The item to remove.

Returns

bool

Implements ICollection<TData>.Remove(TData)

RemoveLeft()

Removes the left child.

Declaration

cs-api-definition
public virtual void RemoveLeft()

RemoveRight()

Removes the left child.

Declaration

cs-api-definition
public virtual void RemoveRight()

ToString()

Returns a string that represents this instance.

Declaration

cs-api-definition
public override string ToString()

Returns

string

A string that represents this instance.

Overrides object.ToString()