Javaループツリーコード


public class Node {

	public Node(String value) {
		this.value = value;
	}
	
	public Node leftNode;//   
	public Node rightNode;//   
	public String value;//      

	public static void read(Node node) {

		if (node == null) {
			return;
		}

		System.out.print(node.value);//    (print    ,      ,   read      )
		read(node.leftNode);
		read(node.rightNode);

	}

	public static void main(String[] args) {

		Node node1 = new Node("A");
		Node node2 = new Node("B");
		Node node3 = new Node("C");
		Node node4 = new Node("D");
		Node node5 = new Node("E");
		Node node6 = new Node("F");

		node1.leftNode = (node2);
		node1.rightNode = (node3);
		node2.leftNode = (node4);
		node3.leftNode = (node5);
		node3.rightNode = (node6);
		read(node1);
	}

}