Please do not give solution in image formate thanku String target and integer numData are read from input. Then, numData alphabetically sorted strings are read from input and each string is appended to a vector. Complete the Search() function: If target is found at index midIndex of the vector, output target, followed by " is found at index " and the value of midIndex. Else if rangeSize is 1, output target, followed by " is not in the list". Otherwise, output target, followed by " is not found at index " and the value of midIndex. End each output with a newline. Ex: If the input is: jaw 9 age all dim egg jaw now pan sat yon then the output is: jaw is found at index 4 Note: string1 == string2 returns true if the two strings are the same, and returns false otherwise.   #include #include #include using namespace std; void Search(vector itemList, string target, int minIndex, int maxIndex) { int midIndex; int rangeSize; rangeSize = (maxIndex - minIndex) + 1; midIndex = (minIndex + maxIndex) / 2; /* Your code goes here */ if (dataVector[middleIndex] == targetName) { cout << targetName << " is found at index " << middleIndex << endl; } else if (rangeSize == 1) { cout << targetName << " is not in the list" << endl; } else if (dataVector[middleIndex] < targetName) { Search(dataVector, targetName, middleIndex + 1, highIndex); } else { Search(dataVector, targetName, lowIndex, middleIndex - 1); } } int main() { string target; vector dataList; int numData; int i; string item; cin >> target; cin >> numData; for (i = 0; i < numData; ++i) { cin >> item; dataList.push_back(item); } Search(dataList, target, 0, dataList.size() - 1); return 0; }   PLEASE MAKE SURE IT OUTPUTS CORRECTLY. THANK YOU.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section7.6: The Standard Template Library (stl)
Problem 8E
icon
Related questions
Question

Please do not give solution in image formate thanku

String target and integer numData are read from input. Then, numData alphabetically sorted strings are read from input and each string is appended to a vector. Complete the Search() function:

  • If target is found at index midIndex of the vector, output target, followed by " is found at index " and the value of midIndex.
  • Else if rangeSize is 1, output target, followed by " is not in the list".
  • Otherwise, output target, followed by " is not found at index " and the value of midIndex.

End each output with a newline.

Ex: If the input is:

jaw 9 age all dim egg jaw now pan sat yon

then the output is:

jaw is found at index 4

Note: string1 == string2 returns true if the two strings are the same, and returns false otherwise.

 

#include <iostream>
#include <vector>
#include <string>
using namespace std;

void Search(vector<string> itemList, string target, int minIndex, int maxIndex) {
int midIndex;
int rangeSize;

rangeSize = (maxIndex - minIndex) + 1;
midIndex = (minIndex + maxIndex) / 2;

/* Your code goes here */
if (dataVector[middleIndex] == targetName) {
cout << targetName << " is found at index " << middleIndex << endl;
} else if (rangeSize == 1) {
cout << targetName << " is not in the list" << endl;
} else if (dataVector[middleIndex] < targetName) {
Search(dataVector, targetName, middleIndex + 1, highIndex);
} else {
Search(dataVector, targetName, lowIndex, middleIndex - 1);
}
}

int main() {
string target;
vector<string> dataList;
int numData;
int i;
string item;

cin >> target;
cin >> numData;
for (i = 0; i < numData; ++i) {
cin >> item;
dataList.push_back(item);
}
Search(dataList, target, 0, dataList.size() - 1);

return 0;
}

 

PLEASE MAKE SURE IT OUTPUTS CORRECTLY. THANK YOU.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr