#include #include #include using namespace std; int bsearchrec(const vector & list, const string & key, int low, int high) // precondition: list.size() == # elements in list // postcondition: returns index of key in list, -1 if key not found { int mid; // middle of current range if (low > high) return -1; //not found else { mid = (low + high)/2; if (list[mid] == key) // found key { return mid; } else if (list[mid] < key) // key in upper half { return bsearchrec(list, key, mid+1, high); } else // key in lower half { return bsearchrec(list, key, low, mid-1); } } } int main() { vector ara; string word; ara.push_back("ali"); ara.push_back("bekir"); ara.push_back("deniz"); ara.push_back("fatih"); ara.push_back("hatice"); ara.push_back("pakize"); ara.push_back("zahide"); cout << "Enter the search name: "; cin >> word; if (bsearchrec(ara, word, 0, ara.size()-1) != -1) cout << word << " found" << endl; else cout << word << " not found" << endl; return 0; }