+ 4
Why this code is not working?
i think it's due to stackoverflow but i m not doing any recursion or not calling any function again and again. https://code.sololearn.com/cR2ATN4dxVgZ/#cpp
3 Antworten
+ 2
The loop never ends, thats why.
The condition low<=high never becomes false when no match is found. As in the end, both become mid...
+ 3
In your code, when you meet the conditions :
arr[mid] > target or arr[mid] < target,
You set high to mid-1 and low to mid +1 respectively, not just mid. Otherwise, the program gets slow.
Change the assignments, and you're done.
+ 3
but why speed becomes slow?