2013-10-29 13 views

回答

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; 
     } 
    } 
    } 
} 
+0

獲取錯誤錯誤C2440:'初始化':無法從'struct __POSITION *'轉換爲'int' – user2499879

+0

您有一箇舊的編譯器。在POSITION中更改自動。我會在我的答案中改變它。 – xMRi