std::vector
重複した要素を含む sを減算するエレガントな方法はありますか?
例:
v1 = { 3, 1, 2, 1, 2, 2 }
v2 = { 2, 4, 3, 3, 3 }
result1 = ??( v1, v2 )
result2 = ??( v2, v1 )
結果を次のようにしたい:
result1 = { 1, 1 }
result2 = { 4 }
私の現在の(そして非常に遅い)解決策:
1) sort v1 and v2
2) use std::unique_copy to v1_uniq, v2_uniq
3) intersect the new vectors with std::set_intersection
4) iterate over v1 and v2 and remove all elements, that are in the intersection 3)
私の他のアイデアは次のとおりです。
1) sort v1 and v2
2) iterate over v1 and v2 and remove duplicates in parallel
しかし、これはちょっとエラーが発生しやすいので、私にはエレガントに見えません。
他のアイデアはありますか?