注意:作业帮助,无需代码。
我在列表框中有一个文件名列表。作为作业的一部分,我想使用二进制搜索实现来搜索文件名。
有人可以帮我理解如何在不使用内置List<T>.BinarySearch(...)
方法的情况下实现二进制搜索吗?
You have to begin with a sorted list of values. Then you just search like you would if you were playing a number guessing game (and were a computer). Pick the middle element of your list. If the number you're searching for isn't equal to the value of the middle element, do the same thing again, but this time on a sub-list that's half the size (since the list is sorted, you know what side of the list your target is on). Just keep doing that until you found the value you're looking for.