i want to create a generic bst , every node has key and value,the methods and will work by the key. do i have to extends comparable in the Tree class? or only in the node class?
i tried to figure out if i have to extends comparable by the node,or only by the key its enough.
public class ThreadedGenericNode<K,V> implements Comparable<ThreadedGenericNode<K,V>>
{
K _key;
V _value;
private ThreadedGenericNode _right;
private ThreadedGenericNode _left;
private ThreadedGenericNode _parent;
private boolean isThreadedRight;
private boolean isThreadedLeft;
public ThreadedGenericNode(K key,V value)
{
this._right = null;
this._left = null;
this._parent = null;
this.isThreadedLeft = true;
this.isThreadedRight = true;
this._key = key;
this._value = value;
}
@Override
public int compareTo(ThreadedGenericNode<K, V> o) {
if(this._key > o._key)
return 1;
return 0;
}
}
i got compile error : "The operator > is undefined for the argument type(s) K"
so i have to use K extends Comparable? or implements? finally the key will be integer, so what is the way to do that?