[Binary search and overflow] Write a C program with a function that performs binary
search. Assume that the elements of the array are unsigned integers, and the following
elements are present along with other elements in the array: 4294967290, 4294967295,
10400.
#include <stdion.h>
size_t bin_search(unsigned int *arr, size_t n, unsigned int target) {
unsigned int m, l = 0, r = n;
while (l < r) {
m = (l + r) / 2;
if (arr[m] == target) return m;
if (arr[m] < targer) {
l = m + 1;
} else {
r = m;
}
}
return -1;
}
int main() { return 0; }
Comments
Leave a comment