i need some help see i have to write code for an array of 20 strings and i have to modify the binary search function im using to accomodate for strings instead of ints i know i still have to sort it so that binary search will work but my problem is how do i write the code for binary search of a string and selection sort of a string or bubble sort either is fine.
any help with this would be greatly appreciated
thanks in advance
// this is a program to binary search string data also problem 7 from page 596
#include <iostream>
#include <string>
using namespace std;
const int SIZE = 20;
string binarySearch(string [], int, int);
int main()
{
string name[SIZE] =
{"Collins, Bill", "Smith, Bart", "Michalski, Joe", "Griffen, Jim",
"Sanchez, Manny", "Rubin, Sarah", "Taylor, Tyrone", "Johnson, Jill",
"Allison, Jeff", "Moreno, Juan", "Wolfe, Bill", "Whitman, Jean",
"Moretti, Bella", "Wu, Hong", "Patel, Renee", "Harrison, Rose",
"Smith, Cathy", "Conroy, Pat", "Kelly, Sean", "Holland, Beth"};
cout << " please enter the person's name that you wish to find in my name data base ";
cin >> nameSearch;
return 0;
}
string binarySearch(string name[], int size, int value)
{
int first = 0,
last = size - 1,
middle,
position = -1;
bool found = false;
while (!found && first <= last)
{
middle = (first + last) / 2;
if (array[middle] == value)
{
found = true;
position = middle;
}
else if (array[middle] > value)
last = middle - 1;
else
first = middle + 1;
}
return position;
}