treeEquals函数 - 在我的私人调用中出错

时间:2018-04-17 22:08:11

标签: java

我无法在私有方法中调用正确的参数。 MyIntSETNode,因此我无法调用MyIntSET,而是调用root ...我仍然在Eclipse中收到错误说明:"This method must return a result of type boolean"

有什么建议吗?

/* Returns true if this tree and that tree "look the same." (i.e. They have
     * the same keys in the same locations in the tree.)
     * Note that just having the same keys is NOT enough.  They must also be in
     * the same positions in the tree.
     */

图片链接如下: enter image description here

***更新:我在我的公开声明中添加了一个返回虚假声明**** 我运行了一个JUnit测试,但仍然失败了......

我错过了什么?

1 个答案:

答案 0 :(得分:0)

您获得的错误是因为如果if条件,则需要指定treeEquals返回的内容,如果根目录不是null则需要继续并比较两次尝试

试试这个

public boolean treeEquals(MyIntSET that) {
  if (root == null && that.getRoot() == null)
    return true;

  return treeEquals(root, that.getRoot());
}

假设您有MyIntSET

的根节点的getter