is there any option to sort vector of points using vector sorted?
that would get ugly. you can make cmp access a global variable type thing (there are ways to globalize data that isnt a pure nasty global variable) and use that vector instead of what was passed in to make the decision. But what in the heck are you actually doing here? If feels like your problem is not well defined, and you are chasing down a rabbit hole that will lead nowhere good.
it feels like whatever you want to do could be done in that for loop.
let me make some assumptions here... you want points to be sorted by whether each point is bigger or smaller than min point thing?
if so, do it in the loop.
make a vector sized nopoints.
grab the back end (nopoints -1):
int backend = nopoints-1; //literally this
and the front:
int frontend = 0;
good times. now this:
bool cmpresult;
1 2 3 4 5 6 7 8
|
for(int i = 0; i < NoPoints; i++)
{
cmpresult = cmp(minimPoint, points[i]);
if(cmpresult)
newvec[frontend++] = points[i];
else
newvec[backend--] = points[i];
}
|
and bam, its sorted as you asked. Or at least that is the idea, I didn't test this.
*** odds are it would perform better if newvec were a vector of integers and it held 'i' instead of points. Then you could refer back to i in the real array for the point data, instead of all that copying of the data. If that works for your application.
you can also do as you were doing, sort the points array with a function that does what you need, then find the entry where it goes from < min to > min and split it. Since it is sorted, you just find the break in other words? That may also be what you were asking.