Example #1
0
 public TreeNodeInsertIntoBST Method(TreeNodeInsertIntoBST root, int val)
 {
     if (root == null)
     {
         return(new TreeNodeInsertIntoBST(val, null, null));
     }
     if (root.val <= val)
     {
         if (root.right == null)
         {
             root.right = new TreeNodeInsertIntoBST(val, null, null);
         }
         else
         {
             Method(root.right, val);
         }
     }
     else
     {
         if (root.left == null)
         {
             root.left = new TreeNodeInsertIntoBST(val, null, null);
         }
         else
         {
             Method(root.left, val);
         }
     }
     return(root);
 }
Example #2
0
 public TreeNodeInsertIntoBST(int val = 0, TreeNodeInsertIntoBST left = null, TreeNodeInsertIntoBST right = null)
 {
     this.val   = val;
     this.left  = left;
     this.right = right;
 }