コード例 #1
0
  public void mirror_tree(Node root) {

    if (root == null) return;

    Node temp = root.left;
    root.left = root.right;
    root.right = temp;

    mirror_tree(root.left);
    mirror_tree(root.right);
  }
コード例 #2
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    LevelOrderTraversal tree = new LevelOrderTraversal();
    tree.root = new Node(1);
    tree.root.left = new Node(2);
    tree.root.right = new Node(3);
    tree.root.left.left = new Node(4);
    tree.root.left.right = new Node(5);
    // tree.root.right.right = new Node(8);

    int height = tree.height(tree.root);

    System.out.println("Height of this Tree is " + height);

    System.out.println("Level order traversal of binary tree is:: ");
    tree.printLevelOrder();

    System.out.println("Level order traversal of binary tree is:: by using Queue ");
    tree.printLevelOrderQueue();

    System.out.println("In order Traversal using Stack is:");
    tree.inorderWithStack();

    System.out.println("Sum Present");
    int res = tree.sumPresent(tree.root, 7, 0);

    System.out.println(res);

    // System.out.println("Result of Float to Int"+(int)2.6);
    System.out.println("Size of the tree is" + (tree.siz_tree(tree.root)));

    // tree.mirror_tree(tree.root);
    System.out.println("Mirror********************************");
    tree.printLevelOrder();

    System.out.println("Sum of Leaf Nodes********************************");
    tree.SumLevelOrderQueue();

    System.out.println("Max Width********************************");
    tree.printMAxWidth(tree.root);

    System.out.println(
        "Is Complete Binary Tree ********************************"
            + tree.isCompleteBineryTree(tree.root));

    System.out.println("Exited!!!");
  }