只想删除重复项。Pool 是vector<pair<string, int>>
,但我似乎以某种方式错过了向量开头的一些元素。任何人都可以验证删除的逻辑吗?谢谢 :)
Pool Master::eliminateDuplicates(Pool generation)
{
for(int i = 0; i < generation.size(); i++)
{
string current = generation.at(i).first;
for(int j = i; j < generation.size(); j++)
{
if(j == i)
{
continue;
}
else
{
string temp = generation.at(j).first;
if(current.compare(temp) == 0)
{
Pool::iterator iter = generation.begin() + j;
generation.erase(iter);
}
}
}
}
return generation;
}