Traversing a tree using Inorder traveral recursively

package in.blogspot.arunj2ee.ds.tree.traversal;

import in.blogspot.arunj2ee.ds.tree.BinaryTreeNode;
import in.blogspot.arunj2ee.ds.tree.util.TreeUtil;

/**
 * Traversing a tree using Inorder traveral recursively
 * Inorder ==> Left, Node, Right
 * Time Complexity: O(n), Space Complexity: O(n)
 * @author Arun.Singh
 *
 */
public class InorderTraversalRecursion {
public static void inOrderTraversal(BinaryTreeNode root) {
if (root != null) {
inOrderTraversal(root.getLeft());
System.out.print(root.getData());
inOrderTraversal(root.getRight());
}
}

public static void main(String[] args) {
inOrderTraversal(TreeUtil.makeSampleBinaryTree());
}

}
========================================================================
Refer Core Classes: http://arunj2ee.blogspot.in/2017/05/tree-core-and-utility-classes.html
========================================================================
Share on Google Plus

About Admin

Arun is a JAVA/J2EE developer and passionate about coding and managing technical team.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment