1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
#include <algorithm>
#include <functional>
int main()
{
int a[] = {43, 36, 14, 36, 16, 30, 45, 11, 16, 40, 31, 48, 39, 30, 17};
std::size_t sz = sizeof a / sizeof *a;
std::cout << "Before partitioning: \n";
for(std::size_t n = 0; n<sz; ++n)
std::cout << a[n] << ' ';
std::cout << '\n';
std::partition(a, a+sz, std::bind2nd(std::less_equal<int>(), 25));
std::cout << "After partitioning: \n";
for(std::size_t n = 0; n<sz; ++n)
std::cout << a[n] << ' ';
std::cout << '\n';
}
|
Before partitioning:
43 36 14 36 16 30 45 11 16 40 31 48 39 30 17
After partitioning:
17 16 14 11 16 30 45 36 36 40 31 48 39 30 43 | |