問題は、抽象型を使用してコンテキスト内のこれら 2 つのオブジェクトを比較する方法がわからないことです。独自のコンパレーターを宣言する必要があるためです。
私はこれまでのところ行きましたが、どういうわけか私は動けなくなりました. Compararable 型は私自身の比較方法のために問題外だと思います.
静的ノード クラス:
static class BinaryNode<ElementType> {
ElementType element;
BinaryNode <ElementType> right;
BinaryNode <ElementType> left;
public BinaryNode(ElementType elm) {
ElementType element = elm;
right=left=null;
}
}
私が混乱する方法の例:
private BinaryNode find( ElementType x, BinaryNode t ) {
while( t != null ) {
if( x.compareTo( t.element ) < 0 )
t = t.left;
else if( x.compareTo( t.element ) > 0 ) // is done with overrite of the comparable method, any Ideas please?
t = t.right;
else
return t; // Match
}
return null; // Not found
}