#include <iostream> // std::cout
#include <algorithm> // std::partition, std::partition_point
#include <vector> // std::vector
bool
IsNegative(
int
i) {
return
(i < 0); }
int
main()
{
std::vector<
int
> data{ 1, -1, 3, -4, 5, 2, -2, 4,
-5, -3 };
std::vector<
int
> negative, positive;
std::stable_partition(data.begin(), data.end(),
IsNegative);
auto
it = std::partition_point(data.begin(), data.end(),
IsNegative);
negative.assign(data.begin(), it);
positive.assign(it, data.end());
std::cout <<
"Negative: "
;
for
(
int
& x : negative)
std::cout <<
' '
<< x;
std::cout <<
'\n'
;
std::cout <<
"Positive: "
;
for
(
int
& x : positive)
std::cout <<
' '
<< x;
std::cout <<
'\n'
;
return
0;
}