通用排序列表,如何找到比所述检索关键字大于所述第一元素的索引? [英] Generic SortedList, How to find the index of the first element that is greater than the search key?

查看:165
本文介绍了通用排序列表,如何找到比所述检索关键字大于所述第一元素的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果不使用扩展的方法(LINQ)。我仅限于.NET 2.0很遗憾。 (是的,它很烂)

Without using extensions methods (LINQ). I am restricted to .NET 2.0 unfortunately. (Yeah, it sucks)

寻找一些接近O(日志(N))。

Looking for something close to O(log(n)).

谢谢对您有所帮助。

推荐答案

要找到的第一个关键是比一个给定的键,你可以使用的密钥列表<$更大C $ C>排序列表< T>。键并执行二进制搜索插值搜索上的按键。这将产生 O(日志(N)) MSDN 指出,一个关键的仰视是 O(1))。

To find the first key that is greater than a given key you could use the list of keys SortedList<T>.Keys and perform a Binary Search or Interpolation Search on the keys. This will yield O(log(n)) (MSDN states that a key look up is O(1)).

这篇关于通用排序列表,如何找到比所述检索关键字大于所述第一元素的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆