How to print binary tree diagram in Java?

How can I print a binary tree in Java so that the output is like:

   4 
  / \ 
 2   5 

My node:

public class Node<A extends Comparable> {
    Node<A> left, right;
    A data;

    public Node(A data){
        this.data = data;
    }
}

21 Answers
21

Leave a Comment