error: ld returned 1 exit status
Can anybody tell me what's causing this error?
/tmp/ccHWwGhh.o: In function main': A2.cpp:(.text+0x407): undefined
reference tobinarysearch(std::string, std::vector >)' collect2: error: ld
returned 1 exit status
Here's my code:
//Located before main()
void binarysearch(string key, vector<string>& f2);
//Located in main()
binarysearch(key, file2);
//key is a string, file2 is a vector<string>
//Here is my code defining the function:
void binaraysearch(string key, vector<string> f2){
sort_vector(f2);
int mid = 0;
int left = 0;
int right = f2.size();
bool found = false;
while (left < right){
mid = left + (left+right)/2;
if (key > f2[mid]){
left = mid + 1;
}
else if(key < f2[mid]){
right = mid;
}
else{
found == true;
}
}
if (found == true){
cout << "YES: " << key << endl;
}
else{
cout << " NO: " << key << endl;
}
}
No comments:
Post a Comment