Package adt.tree

Examples of adt.tree.TreeNode


import adt.tree.TreeNode;

public class Q014_Check_for_Children_Sum_Property_in_a_Binary_Tree {

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


import adt.tree.TreeNode;

public class Q059_Iterative_Method_to_find_Height_of_Binary_Tree {

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

    queue.add(null);
   
    int height = 0;
   
    while (!queue.isEmpty()) {
      TreeNode node = queue.poll();
     
      if (node != null) {
        if (node.left != null) {
          queue.add(node.left);
        }
View Full Code Here

import adt.tree.TreeNode;

public class Q013_Level_order_traversal_in_spiral_form {

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

    boolean leftToRight = true;
   
    curr.push(root);
   
    while (!curr.isEmpty()) {
      TreeNode node = curr.pop();
      System.out.format("%d ", node.val);
     
      if (leftToRight) {
        if (node.left != null) {
          next.push(node.left);
View Full Code Here

import adt.tree.TreeNode;

public class Q010_Find_the_node_with_minimum_value_in_a_Binary_Search_Tree {

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

public class Q044_Construct_Special_Binary_Tree_from_given_Inorder_traversal {
 
  public static void main(String[] args) {
    int[] arr = {1, 5, 10, 40, 30, 15, 28, 20};
    TreeNode root = buildTree(arr, 0, arr.length - 1);
    root.print();
  }
View Full Code Here

      if (arr[i] > arr[max_index]) {
        max_index = i;
      }
    }
   
    TreeNode root = new TreeNode(arr[max_index]);
   
    root.left = buildTree(arr, lo, max_index - 1);
    root.right = buildTree(arr, max_index + 1, hi);
   
    return root;
View Full Code Here

import adt.tree.TreeNode;

public class Q056_Reverse_Level_Order_Traversal {

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

    queue.add(root);
   
    Stack<Integer> stack = new Stack<Integer>();
   
    while (!queue.isEmpty()) {
      TreeNode node = queue.poll();
      stack.push(node.val);
     
      if (node.right != null) {
        queue.add(node.right);
      }
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.