我正在创建二叉树。我不能等于整数,但在我的课程中,它的工作原理。以下是部分代码:等于整数
In tree...
public void add(BTree<T> tree, T newValue){
if(newValue.equals(getValue())){
System.out.println("equals, incrementing count...");
tree.count.incrementAndGet();
}else if(newValue.compareTo(tree.getValue()) > 0){
addRight(tree, newValue);
//It will back here with another node
}else{
addLeft(tree, newValue);
//It will back here with another node
}
}
In main...
BTree<Integer> tree = new BTree<>(0);
tree.add(tree, 1);
tree.add(tree, 1);
tree.add(tree, 1);
tree.add(tree, -1);
System.out.println(tree.getLeftChild().getValue() + "(" + tree.getLeftChild().getCount() + ")" + " " + tree.getRightChild().getValue() + "(" + tree.getRightChild().getCount() + ")");
In console...
-1(1) 1(1)
我该如何等于两个VALUES?
_我如何等于两个VALUES?_ **使用正确实施的'equals()'方法** –
你能告诉我怎么做吗? – rberla
* if(newValue.equals(getValue()))*什么是getValue? – bengoesboom