キーと値の両方を使用してBSTを実装する必要がありますか?次のようなメソッド呼び出しを持つBSTを実装できます。この場合、V値に基づいて、トラバーサルを左ノードと右ノードのどちらに移動するかを各ノードで比較します。
public class BST<V>
{
public void Insert(V value)
{
//implementation
}
public V Remove(V value)
{
//implementation
}
//other methods
}
または、次のようなメソッド呼び出しを持つようにBSTを実装できます。ここで、Kキーは、左ノードと右ノードのどちらにトラバースするかを比較して決定します。
public class BST<K key, V value>
{
public void Insert(K key, V value)
{
//implementation
}
//which of the following would then be the appropriate method signature?
public V Remove(K key)
{
//implementation
}
//or?
public V Remove(V Value)
{
//implementation
}
//other methods
}