How to withdraw binary tree?

Hello! Learn Java came to binary trees, read articles on Habre and so on.. All like clear, but here is the problem how to withdraw binary tree ie I have an empty tree and how to fill it out if you enter from the console and how to bring across. Used the code examples here is an example of the input, but how to bring in the width to get a beautiful tree with the output in the console? Using this input, and when I tried to bring out, as something wrong.
public void add(T1 k, T2 v) {
 Node<t1, t2> x = root, y = null;
 while (x != null) {
 int cmp = k.compareTo(x.key);
 if (cmp == 0) {
 x.value = v;
return;
 } else {
 y = x;
 if (cmp < 0) {
 x = x.left;
 } else {
 x = x.right;
}
}
}
 Node<t1, t2> newNode = new Node<t1, t2>(k, v);
 if (y == null) {
 root = newNode;
 } else {
 if (k.compareTo(y.key) < 0) {
 y.left = newNode;
 } else {
 y.right = newNode;
}
}
 }</t1></t1></t1>
July 2nd 19 at 13:55
0 answer

Find more questions by tags Java