是否有必要使用键和值来实现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
}