About 5,210,000 results
Any time
Open links in new tab
- Viewed 19k times14edited Dec 15, 2012 at 0:24
If you really need 2 vectors, and you can't use GMan's suggestion in the comments:
// where v1 is your original vectorstd::vector<T> v2(std::make_move_iterator(v1.begin() + v1.size()/2),std::make_move_iterator(v1.end()));v1.erase(v1.begin() + v1.size()/2, v1.end());It's still O(n), but you can't do any better than that.
If you need to keep the original vector separate:
std::vector<T> v2(v1.begin(), v1.begin() + v1.size()/2),v3(v1.begin() + v1.size()/2, v1.end());Content Under CC-BY-SA license Slicing a Vector in C++ - GeeksforGeeks
- Question & Answer
Split a Vector into Multiple Smaller Vectors in Java - GeeksforGeeks
Tags:Split A VectorJavaBest way to split a vector into two smaller arrays?
Tags:Split A VectorSplit Vector Into Two Vectors CSplit The Array in CSplit a vector into sub-vectors of size n in C++ - Techie …
May 16, 2024 · Splitting a vector into sub-vectors of a specific size is very easy in C++. We start by determining the total number of sub-vectors of size n formed from the input vector.
Tags:Split A VectorC++C++容器vector的数组片段截取操作 - CSDN博客
Smart way to split a vector into smaller - C++ Forum - C++ Users
Tags:Std Vector SplitSplit Vector Into Two Vectors CC String Split Into VectorSplit a vector into two equal parts in C++ | Techie Delight
Tags:Split A VectorC++How can I split a vector? - MATLAB Answers - MATLAB Central
Tags:Split A VectorMatlab Split VectorNumPy Splitting Array - W3Schools