public TreeNode(TreeNode Left, int Value, TreeNode Right)
public int CompareTo(TreeNode other)
return ((other != null) ? (_Value - other._Value) : 0);
public void InsertNode(TreeNode node)
Console.WriteLine("Value: " + _Value);
Console.WriteLine("Left of " + _Value + "...");
Console.WriteLine("NULL");
Console.WriteLine("Right of " + _Value + "...");
Console.WriteLine("NULL");
public int DepthOfValue(int value)
int depthLeft = _Left.DepthOfValue(value);
int depthRight = _Right.DepthOfValue(value);
public static TreeNode _Root;
public static void Main()
2, 7, 4, 8, 9, 14, 22, 36, 55, 3, 6, 1
Console.WriteLine("Depth of value: " + _Root.DepthOfValue(99));
private static void BuildTree(int[] elements)
foreach (int i in elements)
TreeNode node = new TreeNode(null, i, null);