Package CtCILibrary

Examples of CtCILibrary.TreeNode


    return commonAncestorHelper(root, p, q);
 
 
  public static void main(String[] args) {
    int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    TreeNode root = TreeNode.createMinimalBST(array);
    TreeNode n3 = root.find(1);
    TreeNode n7 = root.find(7);
    TreeNode ancestor = commonAncestor(root, n3, n7);
    System.out.println(ancestor.data);
  }
View Full Code Here


    return null;
 
 
  public static void main(String[] args) {
    int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    TreeNode root = TreeNode.createMinimalBST(array);
    TreeNode n3 = root.find(10);
    TreeNode n7 = root.find(6);
    TreeNode ancestor = commonAncestor(root, n3, n7);
    if (ancestor != null) {
      System.out.println(ancestor.data);
    } else {
      System.out.println("null");
    }
View Full Code Here

    }
    if (root == p && root == q) {
      return root;
    }
   
    TreeNode x = commonAncestorBad(root.left, p, q);
    if (x != null && x != p && x != q) { // Found common ancestor
      return x;
    }
   
    TreeNode y = commonAncestorBad(root.right, p, q);
    if (y != null && y != p && y != q) {
      return y;
    }
   
    if (x != null && y != null) {
View Full Code Here

    }
  } 
 
  public static void main(String[] args) {
    int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    TreeNode root = TreeNode.createMinimalBST(array);
    TreeNode n3 = root.find(9);
    TreeNode n7 = new TreeNode(6);//root.find(10);
    TreeNode ancestor = commonAncestorBad(root, n3, n7);
    if (ancestor != null) {
      System.out.println(ancestor.data);
    } else {
      System.out.println("null");
    }
View Full Code Here

  }
 
  public static void main(String[] args) {
    // Create balanced tree
    int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    TreeNode root = TreeNode.createMinimalBST(array);
    System.out.println("Root? " + root.data);
    System.out.println("Is balanced? " + isBalanced(root));
   
    // Could be balanced, actually, but it's very unlikely...
    TreeNode unbalanced = new TreeNode(10);
    for (int i = 0; i < 10; i++) {
      unbalanced.insertInOrder(AssortedMethods.randomIntInRange(0, 100));
    }
    System.out.println("Root? " + unbalanced.data);
    System.out.println("Is balanced? " + isBalanced(unbalanced));
  }
View Full Code Here

  }
 
  public static void main(String[] args) {
    // Create balanced tree
    int[] array = {0, 1, 2, 3, 5, 6, 7, 8, 9, 10};
    TreeNode root = TreeNode.createMinimalBST(array);

   
    System.out.println("Is balanced? " + isBalanced(root));
   
    root.insertInOrder(4); // Add 4 to make it unbalanced

    System.out.println("Is balanced? " + isBalanced(root));
  }
View Full Code Here

TOP

Related Classes of CtCILibrary.TreeNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.