package cm.com.algorithm.tree;/*** 中序遍历2叉树* 中序遍历是指,对于树中的任意节点来说,先打印它的左子树,然后再打印它本身,最后打印它的右子树** @author liushuai13@meicai.cn* @date 2019-06-11 22:14*/
public class LDRTree {private static final Node root = new Node("A");static {Node b = new Node("B");Node c = new Node("C");root.left = b;root.right = c;Node d = new Node("D");Node e = new Node("E");b.left = d;b.right = e;Node f = new Node("F");Node g = new Node("G");c.left = f;c.right = g;}public static void main(String[] args) {tree(root);}private static void tree(Node node){if (node.left != null){tree(node.left);}System.out.print(node.value + ",");if (node.right != null){tree(node.right);}}private static class Node{Node left;Node right;String value;public Node(String value) {this.value = value;}}
}