In [ ]:
class BinaryTree {
    private Node root;
    
    public boolean add(T value) {
        if (root == null) {
            root = new Node(value);
        } else if (root.value.compareTo(value) == 0) {
            return false;
        } else if (root.value.compareTo(value) < 0) {
            return add(root, "left", value);
        } else {
            return add(root, "right", value);
        }
    }
    
    private boolean add(Node parent, String side, T value) {
        if (side == "left") {
            if (node.left == null) {
                parent.left = new Node(value);
                return true;
            } else {
                if (parent.left.value.compareTo(value) == 0) {
                    return false;
                } else if (parent.left.value.compareTo(value) < 0) {
                    return add(parent.left, "left", value);
                } else {
                    return add(root, "right", value);
                }
            }
        } else {
            if (node.right == null) {
                parent.right = new Node(value);
                return true;
            } else {
            }
        }
    }
    
    public void print() {
        print(root);
    }
    
    private void print(Node node) {
        if (node != null) {
            System.out.print("[");
            print(node.left);
            System.out.print(" " + node.value);
            print(node.right);
            System.out.print("]");
        } else {
            System.out.print("[]");            
        }
    }

    public int count() {
        return count(root);
    }

    private int count(Node node) {
        int total = 0;
        if (node != null) {
            total += 1;
            total += count(node.left);
            total += count(node.right);
        }
        return total;
    }
    
    public static void main(String[] args) {
        BinaryTree bt = new BinaryTee();
        bt.print();
        
        System.out.print("This tree has " + bt.count() + " nodes.");
    }
}