Question
Help me fix... If i delete the last line where it is to print out the string it works fine, but i can't get it
Help me fix... If i delete the last line where it is to print out the string it works fine, but i can't get it to print out the string....
#include
template
int binarySearch(const T list[], T key, int arraySize) { int low = 0; int high = arraySize - 1; while (high >= low)
{ int mid = (low + high) / 2; if (key < list[mid]) high = mid - 1; else if (key == list[mid]) return mid; else low = mid + 1; } return-low - 1; }
int main() { int intList[] = { 2,4,6,8,10 }; double doubleList[] = { 1.1,3.3,5.5,7.7,9.9 }; string stringList[] = { "ABC","DEF","GHI","JKL"};
cout << binarySearch(intList, 4, 5) << endl; cout << binarySearch(doubleList, 7.7, 5) << endl; cout << binarySearch(stringList, "ABC", 4) << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started