lundi 27 juin 2016

"cut and paste" the last k elements of std::vector efficiently?

Is it possible in C++11 "cut and paste" the last k elements of an std::vector A to a new std:::vector B in constant time?

One way would be to use B.insert(A.end() - k, A.end()) and then use erase on A but these are both O(k) time operations.

Mau

Aucun commentaire:

Enregistrer un commentaire