#include #include using namespace std; int BinarySearch(string s, int start, int stop, char key) ; int main () { string array = "bcfghmqtvy"; char c; int pos; for(c = 'a'; c<= 'z';c++) { pos = BinarySearch(array, 0, array.size()-1, c); if (-1 == pos) { cout << c << " is not in " << array << endl; } else { cout << c << " is at position " << pos << " of " << array << endl; } } return 0; } int BinarySearch(string s, int start, int stop, char key) { int mid; if (start > stop) { // we need some indication of not found return -1; } else { mid = (start + stop) /2; if (s[mid] == key) { return mid; } else if (key < s[mid]){ return BinarySearch(s,start, mid-1, key); } else { return BinarySearch(s,mid+1,stop, key); } } }