suppose array, size and element to be found is given

int bisearch(int *sorted_array, int size, int element)

{

int low = 0;

int high = size - 1;

int m;

while (low <= high)

{

m = (low + high) / 2;

if (sorted_array[m] < element)

low = m + 1;

else if (sorted_array[m] == element )

return m;

else

high = m - 1;

}

return -1;

}

## No comments:

## Post a Comment