skip navigation
  • Product Bundles

    DevCraft

    All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:

    • NEW: Design Kits for Figma
    • Online Training
    • Document Processing Library
    • Embedded Reporting for web and desktop

    Web

    Kendo UI UI for jQuery UI for Angular UI for React UI for Vue UI for Blazor UI for ASP.NET Core UI for ASP.NET MVC UI for ASP.NET AJAX

    Mobile

    UI for .NET MAUI

    Document Management

    Telerik Document Processing

    Desktop

    UI for .NET MAUI UI for WinUI UI for WinForms UI for WPF

    Reporting

    Telerik Reporting Telerik Report Server

    Testing & Mocking

    Test Studio Test Studio Dev Edition Telerik JustMock

    CMS

    Sitefinity

    UI/UX Tools

    ThemeBuilder Design System Kit Templates and Building Blocks

    Debugging

    Fiddler Fiddler Everywhere Fiddler Classic Fiddler Everywhere Reporter FiddlerCore

    Free Tools

    VB.NET to C# Converter Testing Framework
    View all products
  • Overview
  • Demos
    • What's New
    • Roadmap
    • Release History
  • Support and Learning

    • Support and Learning Hub
    • First Steps
    • Docs
    • Demos
    • Virtual Classroom
    • Forums
    • Videos
    • Blogs
    • Accessibility
    • Submit a Ticket

    Productivity and Design Tools

    • Visual Studio Extensions
    • Visual Studio Templates
    • Embedded Reporting
  • Pricing
  • Shopping cart
    • Account Overview
    • Your Licenses
    • Downloads
    • Support Center
    • Forum Profile
    • Payment Methods
    • Edit Profile
    • Log out
  • Login
  • Contact Us
  • Try now

Class BinaryTree<TData>

Standard implementation of a binary tree.

Inheritance
System.Object
BinaryTree<TData>
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.

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

Data

Gets or sets the data of this tree.

Declaration
public TData Data { get; set; }
Property Value
TData

The data.

Implements
ITree<T>.Data

Degree

Gets the degree.

Declaration
public int Degree { get; }
Property Value
System.Int32

Implements
ITree<T>.Degree

Height

Gets the height.

Declaration
public virtual int Height { get; }
Property Value
System.Int32

Implements
ITree<T>.Height

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

true if this instance is full; otherwise, false.

IsEmpty

Gets a value indicating whether this tree is empty.

Declaration
public bool IsEmpty { get; }
Property Value
System.Boolean

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
public virtual bool IsLeafNode { get; }
Property Value
System.Boolean

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

Implements
ITree<T>.IsLeafNode

IsReadOnly

Returns false; this tree is never read-only.

Declaration
public bool IsReadOnly { get; }
Property Value
System.Boolean

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

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.

Add(BinaryTree<TData>)

Adds an item to the System.Collections.Generic.ICollection<>.

Declaration
public void Add(BinaryTree<TData> subtree)
Parameters
BinaryTree<TData> subtree

The subtree.

Exceptions
System.NotSupportedException

The System.Collections.Generic.ICollection<> is read-only.

System.InvalidOperationException

The BinaryTree<TData> is full.

System.ArgumentNullException

subtree is null (Nothing in Visual Basic).

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

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

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.Boolean

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

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.

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

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

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

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

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

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
public IEnumerator<TData> GetEnumerator()
Returns
System.Collections.Generic.IEnumerator<TData>

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.Boolean

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.

Explicit Interface Implementations

ITree<TData>.Add(ITree<TData>)

Declaration
void ITree<TData>.Add(ITree<TData> child)
Parameters
ITree<TData> child

Implements
ITree<T>.Add(ITree<T>)

ITree<TData>.FindNode(Predicate<TData>)

Declaration
ITree<TData> ITree<TData>.FindNode(Predicate<TData> condition)
Parameters
System.Predicate<TData> condition

Returns
ITree<TData>

Implements
ITree<T>.FindNode(Predicate<T>)

ITree<TData>.GetChild(Int32)

Declaration
ITree<TData> ITree<TData>.GetChild(int index)
Parameters
System.Int32 index

Returns
ITree<TData>

Implements
ITree<T>.GetChild(Int32)

ITree<TData>.Parent

Gets the parent.

Declaration
ITree<TData> ITree<TData>.Parent { get; }
Returns
ITree<TData>

Implements
ITree<T>.Parent

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

Implements
ITree<T>.Remove(ITree<T>)

Extension Methods

CollectionExtensions.ToEnumerable<T>(T)
EnumerableExtensions.ToEnumerable<T>(T)

See Also

RedBlackTree<TKey, TValue>
Getting Started
  • Install Now
  • Demos
  • SDK Samples Browser
  • Sample Applications
Support Resources
  • Code Library
  • Knowledge Base
  • MVVM Support
  • Videos
  • GitHub SDK Repository
Community
  • Forums
  • Blogs
  • XAML Feedback Portal
  • Document Processing Feedback Portal

Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.