+ 2
Can anyone tell me the short code for performing binary search program
5 Respostas
+ 1
create a recursive function...
store the length of your array or list in a variable (n)...
divide it by 2.....
now get your input number to be searched as (x)....
compare x with (n/2 + 1)th element...
if x is lesser than it, give a recursive call for search function in 1st half i.e. in 1 to (n/2) elements..
else if x is greater than it, give a recursive call for search in the 2nd half of array i.e in (n/2 + 1) to n elements.....
your terminatiin condition will be when u find a match to (x)...... :)
+ 1
#include <stdlib.h>
typedef int (*comparator) (const void* a, const void* b);
void* bsearch(void* key, void* array, int count, int size_of_each_element, comparator comp);
0
thanks for the answer,but it would be a favour if u please write the program
0
I will try to get back to you with a program.... :)
0
thanks suvanditya