问题描述
我完全迷失了。
我想创建一个带两个向量的函数。
这两个向量有x和y坐标的对象,我想做什么
找到相同的x和y坐标中的所有对象,并将所有对象
放在同一个坐标中。
"将所有对象放在同一个坐标中。这是什么意思?
首先编写一个比较函数,告诉我们当一个坐标是少于b $ b时。另一个。然后:
sort(vec.begin(),vec.end(),& my_compare);
听起来你想要删除重复项 - 如果是这样的话,将对象
复制到一个向量中,对它们进行排序,然后擦除多余的对象
如下:
v.erase(std :: unique(v.begin(),v.end()),v。结束());
其中v是对象的排序向量。
Greg
I am completly lost.
I would like to create a function that takes two vectors.
These two vectors have objects with x and y coords, what I want to do
find all the objects in the same x and y coords and put all the objects
in the same coordinate together.
"put all objects in the same coordinate together." What does that mean?
First write a comparison function that tells when one coord is "less
than" another. Then:
sort( vec.begin(), vec.end(), &my_compare );
It sounds like you want to remove duplicates - if so, copy the objects
into a single vector, sort them, and then erase the redundant objects
like so:
v.erase( std::unique(v.begin(), v.end()), v.end());
where v is the sorted vector of objects.
Greg
这篇关于Stumpted:排序向量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!