Package adt.tree

Examples of adt.tree.TreeNode


import adt.tree.TreeNode;

public class Q073B_Print_all_nodes_at_distance_k_from_a_given_node {

  public static void main(String[] args) {
    TreeNode root = Tree.tree15();
   
    // step 1. find the node
    TreeNode node = findNode(root, 3);
    //System.out.println(node.val);
       
    kDistFromNode(root, node, 2);
  }
View Full Code Here


   
    if (root.val == v) {
      return root;
    }
   
    TreeNode left = findNode(root.left, v);
    TreeNode right = findNode(root.right, v);
   
    return (left != null) ? left : right;
  }
View Full Code Here

import adt.tree.TreeNode;

public class Q011_Count_leaf_nodes_in_a_binary_tree {

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

import adt.tree.TreeNode;

public class Q046_Check_whether_a_given_Binary_Tree_is_Complete_or_not {

  public static void main(String[] args) {
    TreeNode root = Tree.bst1();
    boolean res = isCompleteTree(root);
    System.out.println(res);
  }
View Full Code Here

    curr.add(root);
   
    boolean must_have_no_child = false;
   
    while (!curr.isEmpty()) {
      TreeNode node = curr.poll();
     
      if (must_have_no_child) {
        if (node.left != null || node.right != null) {
          return false;
        }
View Full Code Here

import adt.tree.TreeNode;

public class Q015_Convert_an_arbitrary_Binary_Tree_to_a_tree_that_holds_Children_Sum_Property {

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

import adt.tree.TreeNode;

public class Q077_Inorder_predecessor_and_successor_for_a_given_key_in_BST {

  public static void main(String[] args) {
    TreeNode root = Tree.bst2();
    int key = 14;
   
    int floor = getFloor(root, key);
    int ceil = getCeil(root, key);
    System.out.format("%d, %d\n", floor, ceil);
View Full Code Here

import adt.tree.TreeNode;

public class Q036_Convert_a_given_tree_to_its_Sum_Tree {

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

import adt.tree.TreeNode;

public class Q066_Remove_all_nodes_which_donot_lie_in_any_path_with_sum_larger_than_or_equal_to_k {

  public static void main(String[] args) {
    TreeNode root = Tree.tree10();
    root = prune(root, 45, 0);
    root.print();
  }
View Full Code Here

import adt.tree.TreeNode;

public class Q053_Largest_Independent_Set_Problem {
 
  public static void main(String[] args) {
    TreeNode root = Tree.tree8();
    int res = LISS(root);
    System.out.println(res);
  }
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.