Question: The program generates a sorted list of numbers and calls the binary search function to check if a given value appears in the list Your

The program generates a sorted list of numbers and calls the binary search function to check if a given value appears in the list

Your task is to implement the binary search algorithm in the BinSearch.h file, so that the program produces the expected output. If the number we are looking for appears in the list, then return the position in the list where you found it. If it does not, then return -1.

to test code some expected inputs : 27; should output 26, -1, -1

FASTSEARCHING.CPP FILE:

#include #include "BinSearch.h"

using namespace std;

int main() { long size; cin >> size; long* numbers = new long[size];

// This list is sorted for (long i = 0; i < size; i++) { numbers[i] = i; } cout << binSearch(numbers, size, size-1) << endl; cout << binSearch(numbers, size, size+5) << endl; cout << binSearch(numbers, size, -17) << endl; return 0; }

Binsearch.h file here :

#ifndef BinSearch_h #define BinSearch_h

long binSearch(long* list, long n, long val){ // Provide your code here }

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!