Witam
Chciałbym stworzyć drzewo BST, które możę obsługiwać różne typy i je porównywać?
Nie do końca wiem jak za to się zabrać.
Przykładowe klasy:
public class Key {
public Key() {
}
}
public class Node {
private Key key;
private Node left, right;
public Node() {
}
//settery i gerttery
}
public class AlgorithmBST {
private int key;
private AlgorithmBST() {
}
public Node BST_TREE_SEARCH(Node node, Key key)
{
if((node == null) || (node.getKey() == key))
{
return node;
}
if( key < node.getKey() )
{
return BST_TREE_SEARCH(node.getLeft(), key);
}
return BST_TREE_SEARCH(node.getRight(), key);
}
}
Niestety NesBeans zaznacza mi ciąglę błąd:
"operator < cannot be applied to Core.key, Core.key" ?
Co w takim wypadku musiałbym zrobić, jak zorganizować klasę KEY( czy musi implementować interfejs Comparable czy jakiś inny i jak go napisać ) ?