Write a function that receives a vector of integers already sorted in ascending order, an integer n representing the number of elements in this vector, and an integer b. Implement the sequential search algorithm to look for the integer b in the vector. The binary search works as follows: you must look for the element in the position exactly in the half of the vector, if it is the searched one, it returns the number of tests done so far, if it is not the searched one, calculate the midpoint of the half of the vector after assess whether the searched value is greater or less than the value at the middle position. Not finding the value searched, the function must return 0. The name of the function will be called "busca_bin". int bin_search(int array[], int n, int b) { //code }
Write a function that receives a
int bin_search(int array[], int n, int b)
{
//code
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images