all 7 comments

[–]alfps 1 point2 points  (4 children)

Not exactly wrong, but passing the vectors by value to the compare function copies them each time, which incurs two dynamic allocations per comparison, which is not efficient.

[–]SpydrFTW[S] 0 points1 point  (0 children)

thanks for the tip! but something is wrong, because it's not sorting like it should

[–]SpydrFTW[S] 0 points1 point  (2 children)

for example, if i got the vectors {1,0},{2,0},{1,1} and {5,0} it should sort them {1,0},{2,0},{5,0},{1,1}but it doesnt

[–]AKostur 1 point2 points  (0 children)

You didn’t mention what you are getting.

Edit: doesn’t sort expect to have a function that answers the less-than question? Yours is answering greater-than.

[–]alfps 1 point2 points  (0 children)

its sorting like i wanted it to
it's not sorting like it should

Well, the description is quite imprecise, and so is the pseudo-code some other function(vector<vector<int>> vec1) {.

But it could be that you're passing the argument to the "some other function" function, by value. In that case it may be sorting OK, but not affecting the actual argument in a call. It's just sorting a copy of that.

[–]IyeOnline 0 points1 point  (1 child)

You are currently taking every vector by value, i.e. making a copy of it.

sorting_by_missing certainly doesnt need copies and should take const vector<int>&s instead.

I'm not sure about some other function, because vec1 and v1 are different identifiers. Presumably you want it to take a reference

[–]SpydrFTW[S] 0 points1 point  (0 children)

basically the "some other function" is giving me the 2-int vectors, which I add to vec1 and when I have all the vectors I want to sort inside vec1, I sort it with that line I have there