public BSTree(int[] a, bool isBalancedTree) { a = a.Distinct().ToArray(); if (isBalancedTree) { Array.Sort(a); root = BSTBuilder.sortedArrayToBST(a, 0, a.Length - 1); } else { root = new NonEmptyNode(a[0]); root.setLeft(EmptyNode.getInstance()); root.setRight(EmptyNode.getInstance()); for (int i = 1; i < a.Length; i++) { insert(a[i]); } } }
public void buildFromArray(int[] a) { Array.Sort(a); root = BSTBuilder.sortedArrayToBST(a, 0, a.Length - 1); }