O'Reilly logo

C# Data Structures and Algorithms by Marcin Jamro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required