.NET 4 中有二叉搜索树实现吗?
我正在寻找 .NET 4 中的内置二叉搜索树实现。有吗?
I'm looking for a built-in Binary Search Tree implementation in .NET 4. Is there one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我正在寻找 .NET 4 中的内置二叉搜索树实现。有吗?
I'm looking for a built-in Binary Search Tree implementation in .NET 4. Is there one?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
SortedDictionary
类使用 Tree,这就是您想要的吗?请参阅此SO答案进行讨论。
The
SortedDictionary<K,V>
class uses a Tree, is that what you're after?See this SO answer for a discussion.
您可以使用 SortedDictionary
You could use SortedDictionary<TKey, TValue>
另一种选择是使用列表并对其进行排序。然后您可以使用 BinarySearch 方法来查找项目。要维护排序列表,您可以使用 BinarySearch 返回的索引进行插入。如果返回的索引为负,请使用补码(〜运算符)作为插入位置,如果返回的索引为正,则可以在该位置插入(除非您想要设置类似的行为,在这种情况下根本不插入)。
Another option is to use a List and sort it. Then you can use the BinarySearch method to find items. To maintain the sorted list you can use the index returned by the BinarySearch to insert at. If the returned index is negative use the complement (~ operator) as your insert location, if the returned index is positive you can insert at that location (unless you want set like behavior in which case don't insert at all).
C5 库:
C5 library:
http://code.google.com/p/self-balancing-avl-树/。平衡 AVL 树实现,具有连接和拆分操作以及基于 AVL 树的 SortedDictinary 和 SortedMultiDictionary。
http://code.google.com/p/self-balancing-avl-tree/. Balanced AVL tree implementation with concatenate and split operations as well as SortedDictinary and SortedMultiDictionary based on the AVL tree.