Exemplo n.º 1
0
 public void Insert(int data)
 {
     // the data should go where there is already a node, delegate it the insertion to the existing node
     if (data < Data && Left != null)
     {
         Left.Insert(data); // node already exists at left, so it should handle the insertion
     }
     else if (data < Data)
     {
         Left = new BinarySearchTreeNode(data);
     }
     else if (data > Data && Right != null)
     {
         Right.Insert(data); // node already exists at right, so it should handle the insertion
     }
     else if (data > Data)
     {
         Right = new BinarySearchTreeNode(data);
     }
 }
Exemplo n.º 2
0
 public BinarySearchTreeNode(int data)
 {
     Data  = data;
     Left  = null;
     Right = null;
 }