Remove Duplicate Entries in a C++ Vector

后端 未结 1 965
遥遥无期
遥遥无期 2021-02-15 23:10

Just want to remove duplicates. Pool is vector> but I seem to miss some elements at the start of the vector somehow. Can anyone verify

1条回答
  •  一个人的身影
    2021-02-15 23:40

    This is a very common issue.

    Because after you erase an element the position j pointed will skip one element due to the j++ on the for loop. the easiest solution to solve the problem based on your code is to add j-- after generation.erase(iter):

      generation.erase(iter);
      j--;
    

    0 讨论(0)
提交回复
热议问题