Removal

Now you know how to create a new BST, add some nodes to it, as well as check whether a given value already exists in the tree. However, can you also remove an item from a tree? Of course! You will learn how to achieve this goal in this section.

The main method regarding removal of a node from the tree is named Remove and takes only one parameter, the value of the node that should be removed. The implementation of the Remove method is as follows:

public void Remove(T data) 
{ 
    Remove(Root, data); 
} 

As you can see, the method just calls another method, also named Remove. The implementation of this method is more complicated and is as follows:

private void Remove(BinaryTreeNode<T> node, T data) 
{     if (node == null)    { throw new ArgumentException( ...

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.