Add binary_search() (page 462) to your program. Modifymain() to prompt the user for a number to search (until ^D) anddisplay the position of the number in the sorted vector. Try yourprogram for the following user input:
11518403050^D
The output should be:
-12-175-1
int binary_search(vector<int> v, int from, intto, int value)
{
if (from > to)
return -1;
int mid = (from + to) / 2;
if (v[mid] == value)
return mid;
else if (v[mid] < value)
return binary_search(v, mid + 1, to, value);
else
return binary_search(v, from, mid – 1, value);
}
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;
//selection sort function prototype
void selectionSort(vector<int>&v);
//Main method
int main()
{
//file read object
ifstream file;
//vector declaration
vector<int>numbers;
//name of the filr given
PayPal Gateway not configured
PayPal Gateway not configured