自编程二叉树的方法参数问题

Method parameter problem in self programmed Binary tree

我编写了一个二叉树,现在我在按顺序打印时遇到问题。当我调用我的 printIO 方法时,printIO 方法调用另一个方法,该方法需要根节点作为参数(当我递归打印时)该方法每次调用并传递下一个节点。

有没有办法在main中不使用2个方法且不带参数的情况下打印树?

想法:
使临时节点静态并且不要在最终打印方法中使用参数。这没有用,因为我得到了一些例外。有什么想法吗?

主要代码片段

 BinList bl = new BinList();
 bl.add(9);
 bl.add(7);
 ...
 bl.printIO();

列表的代码片段Class:

public void printIO() {
    print_in_order(root);
}

private void print_in_order(Node temp) {
    if (temp != null) {
        print_in_order(temp.left);
        System.out.println(temp.data);
        print_in_order(temp.right);
    }
}

与其在 BinList class 中打印,不如在 BinList class 和 Node class 之间分配责任:

public class BinList {
    private Node root = ...;

    public void printInOrder() {
        if (root != null) {
            root.printInOrder();
        }
    }
}

public class Node {
    private Node left, right;
    private Object data;

    public void printInOrder() {
        if (left != null) {
            left.printInOrder();
        }
        System.out.printl(data);
        if (right != null) {
            right.printInOrder();
        }
    }
}