这个问题是如何正确创建一个新节点以实现insert方法?我正在使用eclipse IDE编写此代码,但遇到问题。
public KeyValueDSBinarySearchTree(Class<K> keyType,
Class<V> valueType,
DSComparator<K> keyComparator) {
ObjectTools.paramNullCheck(keyType, "keyType");
ObjectTools.paramNullCheck(valueType, "valueType");
ObjectTools.paramNullCheck(keyComparator, "keyComparator");
rootNode = null;
count = 0;
levelCount = 0;
lastReplacedPair = null;
lastDeletedPair = null;
}
@Override
public DSKeyValuePair<K, V> insert(K key, V value) {
DSKeyValuePair<K, V> node;
if (rootNode == null) {
count++;
return node;
}
if (key.compareTo(node.getKey())<0) {
rootNode.left = insert(key, value);
}
else {
rootNode.right = insert(key, value);
}
return node;
}