我正在創建二叉樹。我不能等於整數,但在我的課程中,它的工作原理。以下是部分代碼:等於整數
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