コード例 #1
0
        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;
        }
コード例 #2
0
 public void setLeft(TreeNode left)
 {
     this.left = left;
     if (left != null)
         left.parent = this;
 }
コード例 #3
0
 public void setRight(TreeNode right)
 {
     this.right = right;
     if (right != null)
         right.parent = this;
 }
コード例 #4
0
 public TreeNode(int value)
 {
     this.value = value;
     left = right = null;
     size = 1;
 }