【发布时间】:2013-05-30 22:45:45
【问题描述】:
到目前为止我有这个功能:
std::vector<int> f(std::vector& v)
{
std::vector<int> result;
for(unsigned x = 0; x < v.size(); x++)
{
std::vector<int>::iterator location = std::find(result.begin(),result.end(),v[x]);
if(location == result.end())
{
result.push_back(this->v[x]);
}
}
std::sort(result.begin(),result.end());
return result;
}
这个函数从 v 中返回一个无重复元素的排序向量。
有没有更简洁的写法?我读过关于 std::unique 的文章,但这涉及到编辑我不能做的向量。
【问题讨论】:
-
你不能只取
v的价值和std::sort和std::unique吗?