是否需要使用键和值来实现BST?我可以实现有方法调用,如下面的一个BST,将在其中作出比较时的遍历是否应该去基于V值的左节点或右节点每个节点:是否有必要使用键和值来实现BST?
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
}
鉴于此,你会推荐一个包含键和值的普通BST解决方案吗? – 2010-01-12 18:06:44
绝对是的。这就是System.Collection类的工作方式。 – 2010-01-12 18:25:11
你确定你没有考虑IDictionary风格吗? .NET中的ICollection接口实现不提供直接访问来修改元素,而IDictionary提供基于索引/键的访问。就项目访问而言,ICollection仅提供添加和删除。 – 2010-01-21 05:31:34