Everything else in check50 works, but my program can't find 42 in {40, 41, 42} and {39, 40, 41, 42}.

I don't think it's sort's fault, and I've implemented search in the correct way (I think, at least).

Here's my code,please help me out, it would be greatly appreciated!

// code deleted

And I have read many, many other questions and can't seem to find my solution there!

1 Answer 1


In the search function, try replacing if (values[middle] == value) by if (values[middle] == value || values[middle+1] == value). Because middle is an integer and middle = (lower + upper) / 2; works like a floor function so middle may never achieve the value of last index of the array. Not only last index but there would be some other indices too inside the array whose values can't be attained by middle.

  • Thanks for that hint. It helped a lot...
    – AlexPoint
    Jun 23, 2015 at 14:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .