新排序向量到目前爲止,我有這樣的功能:創建無重複
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的內容,但這涉及編輯我無法做到的向量。
不能你只需要通過'價值和'的std :: sort'和v' 'std :: unique'呢? – chris