Generic Binary Search in C#

前端 未结 4 925
醉酒成梦
醉酒成梦 2020-12-16 22:25

Below is my Generic Binary Search. It works okay with the integers type array (it finds all the elements in it). But the problem arises when I use a string array to find any

4条回答
  •  清歌不尽
    2020-12-16 23:06

    The two lines are suspect:

    high = mid + 1
    low = mid + 1
    

    Hmm. Look at the offsets. Of course this is well documented Binary Search Algorithm on Wikipedia. You also do extra work. Examine the pseudo-code and examples closely.

提交回复
热议问题