How to print binary tree diagram in Java?
Asked 07 September, 2021
Viewed 2.9K times
  • 55
Votes

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;
    }
}

20 Answer