Exemple #1
0
 public static void main(String[] args) {
   BNode root1 = new BNode(100);
   root1.left = new BNode(50);
   root1.right = new BNode(300);
   root1.left.left = new BNode(20);
   root1.left.right = new BNode(70);
   List<Integer> first = new ArrayList<Integer>();
   storeInorder(root1, first);
   System.out.println(first);
 }
  public static void main(String[] args) {
    BNode root = new BNode(10);

    root.left = new BNode(8);
    root.right = new BNode(2);

    root.left.left = new BNode(3);
    root.left.right = new BNode(5);
    root.right.left = new BNode(2);
    System.out.println(childrenSumProperty(root));
  }
  /** Used class variable to increment, find efficient one with local variable */
  protected BNode getBSTFromPreOrder(int[] preOrder, int min, int max) {

    if (index >= preOrder.length) {
      return null;
    }
    BNode root = null;

    if (preOrder[index] > min && preOrder[index] < max) {
      root = new BNode(new Data(preOrder[index]));
      index++;
      root.left = getBSTFromPreOrder(preOrder, min, root.data.value);
      root.right = getBSTFromPreOrder(preOrder, root.data.value, max);
    }
    return root;
  }