I have a vector storing the distance to certain reference point along a line. So, I want for example the index where distance is 700 meters or the nearest value to that distance.
I have asumed the vector is sorted, and used lower_bound with success.
The problem is that in real life, errors happen, so I can not assure I’m going to have always a sorted vector, because when storaging data the user may not have followed the line for example.
How can I find the nearest value then, if data is not sorted?
copy your
vectorinto an stlsetand then use the same logic as you have done for vector for finding the element.