-1

CStringList から重複したエントリを削除する方法はありますか?

ありがとう、

4

2 に答える 2

1
void RemoveDuplicates(CStringList &lst)
{
  for (POSITION pos=lst.GetHeadPosition(); pos; )
  {
    const CString &strValue = lst.GetNext(pos);

    // check next hits in the list
    for (POSITION pos2=pos; pos2; )
    {
      // Save current pointer
      POSITION posToDelete = pos2;
      const CString &strValue2 = lst.GetNext(pos2);
      if (strValue==strValue2)
      {
        // remove duplicate
        lst.RemoveAt(posToDelete);

        // There is a chance that we just deleted the follower from the outer loop
        if (posToDelete==pos)
          pos = pos2;
      }
    }
  }
}
于 2013-10-29T13:32:04.123 に答える