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

Tree

The next necessary class is named Tree, and it represents the whole tree. Its code is even simpler than that presented in the preceding section, and is as follows:

public class Tree<T> 
{ 
    public TreeNode<T> Root { get; set; } 
} 

The class contains only one property, Root. You can use this property to get access to the root node, and then you can use its Children property to obtain data of other nodes located in the tree.

It is worth noting that both TreeNode and Tree classes are generic and the same type is used in the case of these classes. For instance, if tree nodes should store string values, the string type should be used in the case of instances of Tree and TreeNode classes.

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