Stumpted:排序向量。 [英] Stumpted: sorting vectors.

查看:111
本文介绍了Stumpted:排序向量。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全迷失了。


我想创建一个带两个向量的函数。

这两个向量有x和y坐标的对象,我想做什么

找到相同的x和y坐标中的所有对象,并将所有对象

放在同一个坐标中。

解决方案

" JoeC" < en ***** @ yahoo.com写信息

新闻:11 ********************** @ i42g2000cwa。 googlegr oups.com ...


>我完全迷失了。


我想创建一个函数需要两个向量。

这两个向量有x和y坐标的对象,我想做什么

找到相同的x和y坐标中的所有对象并放入所有对象

在同一个坐标中。



"将所有对象放在同一个坐标中。这是什么意思?


在文章< 11 ********************** @ i42g2000cwa。 googlegroups .com>,

" JoeC" < en ***** @ yahoo.comwrote:


我完全失去了。


我想要创建一个带两个向量的函数。

这两个向量有x和y坐标的对象,我想做什么

找到同一个x和y中的所有对象coords并将所有对象

放在同一个坐标中。



首先编写一个比较函数,告诉我们当一个坐标是少于b $ b时。另一个。然后:


sort(vec.begin(),vec.end(),& my_compare);




JoeC写道:


我完全丢失了。


我想创建一个函数需要两个向量。

这两个向量有x和y坐标的对象,我想做什么

找到相同的x和y坐标中的所有对象并放入所有对象

在同一个坐标中。



听起来你想要删除重复项 - 如果是这样的话,将对象

复制到一个向量中,对它们进行排序,然后擦除多余的对象

如下:


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.

解决方案

"JoeC" <en*****@yahoo.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...

>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?


In article <11**********************@i42g2000cwa.googlegroups .com>,
"JoeC" <en*****@yahoo.comwrote:

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.

First write a comparison function that tells when one coord is "less
than" another. Then:

sort( vec.begin(), vec.end(), &my_compare );



JoeC wrote:

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.

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:排序向量。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆