2021年1月25日星期一

Erasing from vector by swapping to the end

I am wondering why there is no STL function that deletes an element from a vector by swapping it to the end and then removing it. Is there a better data structure than std::vector if you don't care about the actual order of elements and still want very fast traversal?

Note that using std::remove and std::erase is not the same because this is linear time instead of constant time as the order has to be preserved.

https://stackoverflow.com/questions/65893596/erasing-from-vector-by-swapping-to-the-end January 26, 2021 at 07:01AM

没有评论:

发表评论