void binarysearch(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;
left = right;
}
}
cout << "out of while loop" << endl;
if (found == true){
cout << "YES: " << key << endl;
}
else{
cout << " NO: " << key << endl;
}
found = false;
}
当我运行它时,它会自动终止并显示“分段错误”,但没有给出行号。这甚至意味着什么,为什么我会遇到这个错误?
提前致谢