Package adt.tree

Examples of adt.tree.TreeNode


import adt.tree.TreeNode;

public class Q054_Find_if_there_is_a_triplet_in_a_Balanced_BST_that_adds_to_zero {

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


import adt.tree.TreeNode;

public class Q022_Maximum_width_of_a_binary_tree {

  public static void main(String[] args) {
    TreeNode root = Tree.tree1();
    int width = getTreeWidth(root);
    System.out.println(width);
   
    int max = getMaxWidth(root);
    System.out.println(max);
View Full Code Here

   
    int count = 0;
    int width = 0;
   
    while (!curr.isEmpty()) {
      TreeNode node = curr.poll();
      count++;
     
      if (node.left != null) {
        next.add(node.left);
      }
View Full Code Here

import adt.tree.TreeNode;

public class Q061_Difference_between_sums_of_odd_level_and_even_level_nodes_of_a_Binary_Tree {

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

     *               /  \
     *             65    80
     *            / \
     *           90  17
     */
    TreeNode root = Tree.tree6();
    findDepth(root, 1);
    System.out.println(max);
  }
View Full Code Here

import adt.tree.TreeNode;

public class Q001_Tree_Traversals {
 
  public static void main(String[] args) {
    TreeNode root = Tree.tree1();
   
    System.out.format("Preorder\n");
    preorder(root);
    System.out.format("\n");
    preorderR(root);
View Full Code Here

  //
  //  1 2 4 5 3 6 7
  // -------------------------
  static void preorder(TreeNode root) {
    Stack<TreeNode> stack = new Stack<TreeNode>();
    TreeNode curr = root;
   
    while (!stack.isEmpty() || curr != null) {
      if (curr != null) {
        System.out.format("%d ", curr.val);
        stack.push(curr);
View Full Code Here

  //
  //  4 2 5 1 6 3 7
  // -------------------------
  static void inorder(TreeNode root) {
    Stack<TreeNode> stack = new Stack<TreeNode>();
    TreeNode curr = root;
   
    while (!stack.isEmpty() || curr != null) {
      if (curr != null) {
        stack.push(curr);
        curr = curr.left;
View Full Code Here

    Stack<TreeNode> out_stack = new Stack<TreeNode>();
   
    in_stack.push(root);
   
    while (!in_stack.isEmpty()) {
      TreeNode node = in_stack.pop();
      out_stack.push(node);
     
      if (node.left != null) {
        in_stack.push(node.left);
      }
     
      if (node.right != null) {
        in_stack.push(node.right);
      }
    }
   
    while (!out_stack.isEmpty()) {
      TreeNode node = out_stack.pop();
      System.out.format("%d ", node.val);
    }
  }
View Full Code Here

   
    Queue<TreeNode> queue = new LinkedList<TreeNode>();
    queue.add(root);
   
    while (!queue.isEmpty()) {
      TreeNode node = queue.poll();
      System.out.format("%d ", node.val);
     
      if (node.left != null) {
        queue.add(node.left);
      }
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.