I'm trying to do a binary search on a vector of strings and keep getting this error. I just can't for the life of me figure out what is wrong, so if anyone could help me out that'd be really amazing.
This is the PhoneEntry header file with the class declaration:
And here's the part of the program that I'm having issues with:Code:using namespace std; #include<string> #include<iostream> #include<fstream> #include<vector> #include"phoneNumber.h" class PhoneEntry { private: PhoneNumber eNumber; string firstName, lastName; void writeDots(ostream&, int) const; public: istream& readEntry(istream&); ostream& writeEntry(ostream&) const; bool greaterAlpha(const PhoneEntry &); void mySort(vector<PhoneEntry>&, int); PhoneEntry key(string, string); };
Code:int binarySearch(PhoneEntry keyP, vector<PhoneEntry> entryNames) { int low = 0, mid, high = entryNames.size()-1; while (low <= high) { mid = (low + high) / 2; if (keyP.greaterAlpha(entryNames[mid])) //greaterAlpha compares the two strings and returns true or false based on alphabetical order high = mid - 1; else if (!keyP.greaterAlpha(entryNames[mid])) low = high + 1; else low = high + 1; } if (keyP == entryNames[mid]) //This is the line where I keep getting the error return mid; else return (mid * -1); };


Reply With Quote
Bookmarks