#include <iostream>
#include <algorithm>
#include <iterator>
template <typename iter_type>
void print(iter_type beg, iter_type end)
{
std::cout << *beg;
while (++beg != end)
std::cout << ' ' << *beg;
std::cout << '\n';
}
int main()
{
int num[] = { 4, -2, -8, 1, 7, 9, -23, -6, 56, 23 };
std::cout << "before partition\n\t";
print(std::begin(num), std::end(num));
auto p = std::partition(std::begin(num), std::end(num), [](int n) {return n < 0; });
std::cout << "\nafter partition\n\t";
print(std::begin(num), std::end(num));
std::cout << "\nnegative numbers (" << p - std::begin(num) << ")\n\t";
print(std::begin(num), p);
std::cout << "\npositive numbers (" << std::end(num) - p << ")\n\t";
print(p, std::end(num));
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8aXRlcmF0b3I+Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgaXRlcl90eXBlPgp2b2lkIHByaW50KGl0ZXJfdHlwZSBiZWcsIGl0ZXJfdHlwZSBlbmQpCnsKICAgIHN0ZDo6Y291dCA8PCAqYmVnOwoKICAgIHdoaWxlICgrK2JlZyAhPSBlbmQpCiAgICAgICAgc3RkOjpjb3V0IDw8ICcgJyA8PCAqYmVnOwoKICAgIHN0ZDo6Y291dCA8PCAnXG4nOwp9CgoKaW50IG1haW4oKQp7CiAgICBpbnQgbnVtW10gPSB7IDQsIC0yLCAtOCwgMSwgNywgOSwgLTIzLCAtNiwgNTYsIDIzIH07CgogICAgc3RkOjpjb3V0IDw8ICJiZWZvcmUgcGFydGl0aW9uXG5cdCI7CiAgICBwcmludChzdGQ6OmJlZ2luKG51bSksIHN0ZDo6ZW5kKG51bSkpOwoKICAgIGF1dG8gcCA9IHN0ZDo6cGFydGl0aW9uKHN0ZDo6YmVnaW4obnVtKSwgc3RkOjplbmQobnVtKSwgW10oaW50IG4pIHtyZXR1cm4gbiA8IDA7IH0pOwoKICAgIHN0ZDo6Y291dCA8PCAiXG5hZnRlciBwYXJ0aXRpb25cblx0IjsKIC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