title: C# Binary Search Tree Problem
body: <p>I have programmed a binary search tree with method Add(). But it is not working. When I add number to the tree, root is still empty. Why?</p>
  
  <p>EDIT: Code on pastebin, here I am havig some problems with displaying <a href="http://pastebin.com/jvP0WwhR" rel="nofollow">http://pastebin.com/jvP0WwhR</a></p>
  
  <pre><code>using System;
  
  namespace bst
  {
      public class Node
      {
          public int value;
          public Node Right = null;
          public Node Left = null;
  
          public Node(int value)
          {
              this.value = value;
          }
      }
  
  
  
      public class BST
      {
          public Node Root = null;
  
          public BST()
          {
          }
  
          public void Add(int new_value)
          {
              if(Search(new_value))
              {
                  Console.WriteLine("Zadaná value (" + new_value + ") se ve stromu už nachází");
              }
              else
              {
                  AddNode(this.Root,new_value);
              }
  
          }
  
          public void AddNode(Node Actual, int new_value)
          {
                  if(Actual == null)
                  {
                      Actual = new Node(new_value);
                  }
                  else if(new_value &lt; Actual.value)
                  {
                      AddNode(Actual.Left,new_value);
                  }
                  else if(new_value &gt; Actual.value)
                  {
                      AddNode(Actual.Right,new_value);
                  }
  
          }
  
  
          public bool Search(int hledane)
          {
              Node Actual = this.Root;
  
              while(Actual != null)
              {
                  if(hledane &lt; Actual.value)
                  {
                      Actual = Actual.Left;
                  }
                  else if(hledane &gt; Actual.value)
                  {
                      Actual = Actual.Right;
                  }
                  else
                  {
                      return true;
                  }
              }
              return false;
  
          }
  
          public void Display()
          {
              DisplayUndertree(this.Root,0);
          }
  
          public void DisplayUndertree(Node EnterNode, int deep)
          {
              if(EnterNode != null)
              {
                  for(int i=1; i&lt;=deep; i++)
                  {
                      Console.Write("\t");
                  }
                  Console.WriteLine(EnterNode.value);
              }
  
              if(EnterNode.Left != null)
              {
                  DisplayUndertree(EnterNode.Left,deep+1);
              }
  
              if(EnterNode.Right != null)
              {
                  DisplayUndertree(EnterNode.Right,deep+1);
              }
          }
      }
  
      class Program
      {
          public static void Main(string[] args)
          {
              BST strom = new BST();
              Console.WriteLine(strom.Search(5));
              strom.Add(5);
              Console.WriteLine(strom.Search(5));
              Console.WriteLine(strom.Root.value);
  
  
              //strom.Display();
  
              Console.Write("Press any key to continue . . . ");
              Console.ReadKey(true);
          }
      }
  }
  </code></pre>