Ich versuche, eine BST zu implementieren. Ich arbeite daran, einen Schlüssel und einen Wert zu einem Knoten hinzuzufügen. Das habe ich bisher. Aber ich bekam immerBST: Konstruktorknoten in der Klasse. Der Knoten kann nicht auf bestimmte Typen angewendet werden.
constructor Node in class EMD<K,V>. Node cannot be applied to given types.
required: no arguments; found K,V;
Wie behebe ich das?
class EMD<K extends Comparable<K>, V> implements RangeMap<K,V> {
class Node {
Node left;
Node right;
KVPair<K,V> kv;
}
private Node root;
public void add(K key, V value) {
// TODO: Implement me(basic score)
root = add (root, key, value);
}
private Node add(Node x, K key, V value){
if (x == null){
return new Node (key, value);
int cmp = key.compareTo(x.key);
if (cmp < 0){
x.left = add(x.left, key, value);}
else if (cmp > 0){
x.right = add(x.right, key, value);}
else if (cmp == 0){
x.value = value;}
}
return x;
}
wäre das korrekt? Klassenknoten { Knoten links; Knoten rechts; KVPair kv; K-Taste; V-Wert; öffentlicher Knoten (K-Schlüssel, V-Wert) { \t \t \t this.key = Schlüssel; \t \t \t this.value = Wert; \t \t} } –
amelia