tom davies

Ranch Hand

Posts: 168

posted 4 years ago

- 1

I am trying to make a binary search for my array. Sometimes it works fine, other times it prints out the error message, and the different variables i use in my calculation.

I have found that when the error occurs, mid is always one behind the value found at that point in the array.

An example error output:

error

number to find :> 4678 Mid :> 4677 ArrayMid :> 4678 lowerBound :> 4673 upperBound :> 4681

and the search algorithm:

I have found that when the error occurs, mid is always one behind the value found at that point in the array.

An example error output:

error

number to find :> 4678 Mid :> 4677 ArrayMid :> 4678 lowerBound :> 4673 upperBound :> 4681

and the search algorithm: