使用“unique()”在 C++ 中的向量向量上
我希望这不是一个重复的问题,但如果是,请随时为我指出正确的方向。
我有一个 vector
。
是否可以对此使用 unique()
?例如:
vector<vector<int> > myvec;
//blah blah do something to myvec
vector<vector<int> >::interator it = unique(myvec.begin(), myvec.end());
myvec.begin()
到 it
的范围是否唯一?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,只要你的向量是排序的。请参阅unique () STL 文档了解详细信息。
这是一个用法示例:
Yes, as long as your vector is sorted. See unique () STL documentation for details.
Here is an example of usage:
看起来它应该可以工作——它会在两个
vector
对象上调用 == 运算符,这样就应该可以工作。请注意,该运算符适用于重复项组,因此如果您的重复项尚未分组,您可能必须对外部向量进行排序。
参考:http://www.sgi.com/tech/stl/unique.html< /a>
Looks like it should work -- it would call the == operator on two
vector<int>
objects so that should work.Note that the operator works on groups of duplicates so you may have to sort your outer vector if your duplicates are not grouped already.
Ref: http://www.sgi.com/tech/stl/unique.html