Course Solutions Uncategorized (Solved) : Add Binarysearch Page 462 Program Modify Main Prompt User Number Search D Display Position Q29708155 . . . .

(Solved) : Add Binarysearch Page 462 Program Modify Main Prompt User Number Search D Display Position Q29708155 . . . .

 

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

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post