Tree

The whole tree is represented by an instance of the BinarySearchTree class, which inherits from the BinaryTree generic class, as in the following code snippet:

public class BinarySearchTree<T> : BinaryTree<T>  
    where T : IComparable 
{ 
} 

It is worth mentioning that a type of data, stored in each node, should be comparable. For this reason, it has to implement the IComparable interface. Such a requirement is necessary because the algorithm needs to know the relationships between values.

Of course, it is not the final version of the implementation of the BinarySearchTree class. You will see how to add new features, such as lookup, insertion, and removal of nodes, in the following sections.

Get C# Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.