Package adt.tree

Examples of adt.tree.TreeNode


import adt.tree.TreeNode;

public class Q020_Root_to_leaf_path_sum_equal_to_a_given_number {

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


import adt.tree.TreeNode;

public class Q069_Find_next_right_node_of_a_given_key {

  public static void main(String[] args) {
    TreeNode root = Tree.bst1();
    TreeNode node = getNextRight(root, 8);
    if (node != null) {
      System.out.format("%d\n", node.val);
    } else {
      System.out.println("NULL");
    }
View Full Code Here

   
    Queue<TreeNode> queue = new LinkedList<TreeNode>();
    queue.add(root);
    queue.add(null);
   
    TreeNode prev = null;
   
    while (!queue.isEmpty()) {
      TreeNode node = queue.poll();
     
      if (node != null) {
        if (node.val == key) {
          return prev;
        }
View Full Code Here

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

import adt.tree.TreeNode;

public class Q076_Find_the_maximum_path_sum_between_two_leaves_of_a_binary_tree {

  public static void main(String[] args) {
    TreeNode root = Tree.tree17();
    maxPathSum(root);
    System.out.println(max);
  }
View Full Code Here

import adt.tree.TreeNode;

public class Q057_Remove_BST_keys_outside_the_given_range {

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

    // base case
    if (root == null) {
      return null;
    }
   
    TreeNode left = removeOutsideRange(root.left, min, max);
    TreeNode right = removeOutsideRange(root.right, min, max);
   
    if (root.val < min) {
      return right;
    }
   
View Full Code Here

import adt.tree.TreeNode;

public class Q026_Inorder_Successor_in_Binary_Search_Tree {

  public static void main(String[] args) {
    TreeNode root = Tree.bst2();
    TreeNode node = Tree.getTreeNode(root, 8);
   
    TreeNode successor = inOrderSuccessor(root, node);
    if (successor == null) {
      System.out.println("null");
    } else {
      System.out.println(successor.val);
    }
View Full Code Here

      return minNode(node.right);
    }
   
    // 否则从 root 开始找一直到找到 node 为止
    // 在找的过程中,如果 root 的值比 node 大,那么记录下它
    TreeNode succ = null;
   
    while (root != null) {
      if (root.val > node.val) {
        succ = root;
        root = root.left;
View Full Code Here

import adt.tree.TreeNode;

public class Q007_Print_out_all_of_its_root_to_leaf_paths_one_per_line {

  public static void main(String[] args) {
    TreeNode root = Tree.tree1();
    printPath(root, new ArrayList<Integer>());
  }
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.