+ 3

Binary Search with Sorting Algorithm HELP

Binary search not working, but sorting does. https://code.sololearn.com/c6jdpzBRg517/?ref=app

25th Jun 2017, 5:45 PM
Joe McMillan
Joe McMillan - avatar
3 Answers
+ 4
The problem is that the value of 'l', which is your 'high' is always 0. In other words, after I input the length of the array, you never change the value of l. Fix/ Add this at around line 14: num = sc.nextInt(); a = new int[num]; l = a.length-1; <<<<------(this) PS: This code was fairly difficult to read, I suggest you work on the readability of your code.
25th Jun 2017, 6:16 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
Check out my code, I fixed the search for you. https://code.sololearn.com/cKhIm6TEvFU3/?ref=app
25th Jun 2017, 6:06 PM
Frederik Bussler
Frederik Bussler - avatar
+ 2
works wonders, thanks for helping!
26th Jun 2017, 6:59 AM
Joe McMillan
Joe McMillan - avatar