Re: Programming help - Binary Search

2020-02-13 Thread adnan
Thanks. I missed that equal case.

Re: Programming help - Binary Search

2020-02-13 Thread cblake
I think you just need `hi >= lo` instead of just `>` (the Java code you posted has that). You should also be told that this is in the Nim stdlib as `algorithm.binarySearch`, although it does use the simpler -1 return to signal "not found" rather than `Option[T]` stuff.

Programming help - Binary Search

2020-02-13 Thread adnan
Hi, my question is not specific to Nim but I'm asking it here because I'm using it :) I am debugging a simple iterative binary search but it seems to fail my test. Here's my impl: import options proc index_of*[T](list: openArray[T]; key: T): Option[int] = var