Package adt.tree

Examples of adt.tree.TreeNode


import adt.tree.TreeNode;

public class Q073A_Print_all_nodes_that_are_at_distance_k_from_a_leaf_node {

  public static void main(String[] args) {
    TreeNode root = Tree.tree15();
    int k = 1;
    printKDistantfromLeaf(root, k);
  }
View Full Code Here


import adt.tree.TreeNode;

public class Q040_Vertical_Sum_in_a_given_Binary_Tree {

  public static void main(String[] args) {
    TreeNode root = Tree.tree1();
    Map<Integer, ArrayList<TreeNode>> map = new TreeMap<Integer, ArrayList<TreeNode>>();
   
    verticalSum(root, 0, map);
   
    // print out the sums
    for (Map.Entry<Integer, ArrayList<TreeNode>> entry : map.entrySet()) {
      int sum = 0;
      ArrayList<TreeNode> list = entry.getValue();
      for (int i = 0; i < list.size(); i++) {
        TreeNode node = list.get(i);
        sum += node.val;
      }
     
      System.out.format("%d ", sum);
    }
View Full Code Here

import adt.tree.TreeNode;

public class Q005_Delete_a_Tree {
 
  public static void main(String[] args) {
    TreeNode root = Tree.tree1();
    deleteTree(root);
  }
View Full Code Here

import adt.tree.TreeNode;

public class Q012_Check_if_a_binary_tree_is_BST_or_not {

  public static void main(String[] args) {
    TreeNode root = Tree.bst2();
   
    boolean res1 = isBSTPreorder(root);
    System.out.println(res1);
   
    boolean res2 = isBSTPostorder(root);
View Full Code Here

    if (root == n1 || root == n2) {
      return root;
    }
   
    // Look for keys in left and right subtrees
      TreeNode left_lca  = findLCA(root.left, n1, n2);
      TreeNode right_lca = findLCA(root.right, n1, n2);
     
      // If both of the above calls return Non-NULL, then one key
      // is present in once subtree and other is present in other,
      // So this node is the LCA
      if (left_lca != null && right_lca != null
View Full Code Here

import adt.tree.TreeNode;

public class Q004_Find_the_Maximum_Depth_or_Height_of_a_Tree {

  public static void main(String[] args) {
    TreeNode root = Tree.tree1();
    int height = maxDepth(root);
    System.out.println(height);
  }
View Full Code Here

import adt.tree.TreeNode;

public class Q047_Boundary_Traversal_of_binary_tree {

  public static void main(String[] args) {
    TreeNode root = Tree.bst2();
    printBoundary(root);
  }
View Full Code Here

import adt.tree.TreeNode;

public class Q030_Print_BST_keys_in_the_given_range {

  public static void main(String[] args) {
    TreeNode root = Tree.bst2();
    print(root, 10, 22);
  }
View Full Code Here

import adt.tree.TreeNode;

public class Q027A_Find_kth_smallest_element_in_BST {

  public static void main(String[] args) {
    TreeNode root = Tree.bst2();
    TreeNode node = findKthSmallest(root, 5);
    System.out.println(node.val);
  }
View Full Code Here

    if (root == null || k < 1) {
      return null;
    }
   
    Stack<TreeNode> stack = new Stack<TreeNode>();
    TreeNode curr = root;
   
    int count = 1;
    while (!stack.isEmpty() || curr != null) {
      if (curr != null) {
        stack.push(curr);
View Full Code Here

TOP

Related Classes of adt.tree.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.