I am new to c++. I have a vector with size n. I want to search in the vector ad store positive and negative values in the new vectors. I don't know the number of positive and negative values.
Can anyone help me?
Here is yet another solution using std::partition_copy from the standard library:
std::vector<int> src, neg, pos;
std::partition_copy(
src.begin(), src.end(),
back_inserter(neg),
back_inserter(pos),
[](int value){ return value < 0; }
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With