【问题标题】:Sending in-order traversal elements to array将有序遍历元素发送到数组
【发布时间】:2016-05-17 04:14:52
【问题描述】:
private void inOrder(BSTNode root) {
        if (root.getElem().equals(null)) {
            return;
        }
        inOrder(root.getLChild());
        // print to array, increment 2
        inOrder(root.getRChild());
}

所以我相信打印到数组发生在注释行,因为这通常是当前节点的输出位置,但不确定如何将有序元素发送到数组中?如果它需要一个额外的参数或不同的返回类型来使它工作,那没关系,我可以调整它,因为它是一个辅助方法。

【问题讨论】:

    标签: java arrays tree binary-tree binary-search-tree


    【解决方案1】:

    两件事:

    1. 您必须将 arrayindex 传递给您的方法(签名更改)。
    2. 你可以简单地添加这一行而不是评论:

      array[index++]= root.getData();
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-03
      • 2015-01-16
      • 1970-01-01
      • 2021-08-12
      • 2017-09-01
      • 2013-06-23
      相关资源
      最近更新 更多