0

Can anyone of you experts see where I am going wrong?

I am trying to make a binary search from first principles but am hitting a brick wall. It's probably a basic thing. Apologies if it is. Many thanks. P https://code.sololearn.com/ccw9nz78lSNQ/?ref=app

10th Mar 2021, 1:56 PM
Phillipa Austin-Seymour
Phillipa Austin-Seymour - avatar
2 Antworten
+ 2
Gets stuck in infinite loop , need to re calculate mid value everytime until the number is found. var low: Int = 0 var high: Int = orderedList.size-1 var mid: Int=0; var itemFound = false do { mid=(low+high)/2 if (searchTerm == orderedList[mid]) {
10th Mar 2021, 2:15 PM
Abhay
Abhay - avatar
0
Thank you so much! That worked. 😊.
10th Mar 2021, 6:56 PM
Phillipa Austin-Seymour
Phillipa Austin-Seymour - avatar