![]() |
binary search question.
i know it might sound stupid asking this but im stumped.
how could i modify the binary search code so as to find an element in the array which is just less than the element(ie wat i want t do is to find the elemnt which is anyway in the code and to find the element which is closest to it from the lesser side incase the elemnt i need is not in the array) here's my code: Code:
|
Re: binary search question.
Asking the above question does not sound as stupid as your code :rofl:
Look at your bs func : the beg and end, you are working with are the values ! You should work with index, instead. Correct code will be : Code: c++
I have changed a[i] = 2*i; in the main function, so that you can test with odd numbers as target. Sample I/O : Code: Test-Run
|
Re: binary search question.
thanks a million!!!:pleased:
|
Re: binary search question.
My pleasure :happy:
|
| All times are GMT +5.5. The time now is 09:50. |