private static TreeNode CreateMinimalBST(int[] array, int start, int end) { if (end < start) return null; int mid = (start + end) / 2; TreeNode root = new TreeNode(array[mid]); root.setLeft(CreateMinimalBST(array, start, mid-1)); root.setRight(CreateMinimalBST(array, mid+1, end)); return root; }
public void setLeft(TreeNode left) { this.left = left; if (left != null) left.parent = this; }
public void setRight(TreeNode right) { this.right = right; if (right != null) right.parent = this; }
public TreeNode(int value) { this.value = value; left = right = null; size = 1; }