0
我对我的二进制搜索树类的包含方法感到困惑。二进制搜索树包含方法Java参数
public boolean contains(Object o) {
if (o == null)
{
throw new NullPointerException("Null Items are not allowed in the tree");
}
if (root.item.equals(o))
{
return true;
}
return false;
}
这里是我的头:
public class BSTreeSet<E extends Comparable<E>> implements Set<E>, CompareCount {
private Node root =null;
private int size;
private int compareCount;
我的JUnit测试接收到错误:
public void testContains() {
BSTreeSet<Integer> testSet = new BSTreeSet<Integer>();
testSet.clear();
testSet.add(10);
testSet.add(20);
testSet.add(30);
testSet.add(40);
testSet.add(15);
testSet.add(25);
testSet.add(5);
testSet.add(1);
assertTrue("contains must return true for the element 10", testSet.contains(10));
我感到困惑如何搜索降权和左侧用适当的变量...我知道这是几乎相同的问题,但我卡住了!
你是什么意思的“当接口创建此方法”? – qqilihq
当我添加未实现的方法,它会创建一个看起来像下面这样的默认方法: 公共布尔包含(对象为arg0){ \t \t \t \t返回FALSE; – EllioLintt
如果你的接口需要一个Object参数,你需要使用它。但请注意,您的问题中的“包含”方法实际上有两个**参数。 – qqilihq