Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2022 Workshops 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 In Computer And Information Science 33

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Alfred Taudes ,Atif Mashkoor ,Johannes Sametinger ,Jorge Martinez-Gil ,Florian Sobieczky ,Lukas Fischer ,Rudolf Ramler ,Maqbool Khan ,Gerald Czech

1st Edition

3031143426, 978-3031143427

More Books

Students also viewed these Databases questions

Question

What is the most common design trap, and how does it occur?

Answered: 1 week ago