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
2 Answers
+ 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])
{
0
Thank you so much! That worked. đ.