Question: bool binarySearch(std::vector myvector, int search, std::string type) { int mid; int low = 0; int high = myvector.size() - 1; while (low midVlaue ){ low

bool binarySearch(std::vector myvector, int search, std::string type) { int mid; int low = 0; int high = myvector.size() - 1; while (low <= high) { mid = (high + low) / 2; int midVlaue = myvector[mid].putIsbn(); int find;

if(type == myvector[mid].putType()) find = 0; if (search == midVlaue && find == 0 ){ return mid; } else if (search > midVlaue ){ low = mid + 1; } else { high = mid - 1; } } return false; } bool linearSearch(std::vectormyvector, int search, std:: string type) { for (int i = 0; i < myvector.size(); i++) { if (search == myvector[i].putIsbn() && type == myvector[i].putType()) { return true; } } return false; }

I would like to know how to find integer and string in the vector with binary search. I can find with linear search but I don't know how to do with binary search

For example,

34,new

45,used

35,digital

I want to find "34,new". It has to be same number and type. If I find "34,used" it shouldn't be executable. When I find with linear search the answer correct but binary sear is incorrect.

please help me with add in binary search function. Thanks

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!