1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <algorithm>
#include <iterator>
static int arrayN[] = { 1,3,2,4,5,19,7,8,6,16,11,12,13,14,15,10,17,18,8,20 };
void arrayFunction(int n[], size_t arraySize, const int divider)
{
auto itr = std::stable_partition(n, n+arraySize, [÷r](int n){return n > divider;});
//http://en.cppreference.com/w/cpp/algorithm/stable_partition
//http://en.cppreference.com/w/cpp/algorithm/partition
if (itr == n)
{
std::cout << "No array element is greater than the divider \n";
}
else
{
std::cout << "The array elements greater than " << divider << "\n ";
std::copy(n, itr, std::ostream_iterator<int>(std::cout, " "));
//http://en.cppreference.com/w/cpp/algorithm/copy
std::cout << "\nThe array elements less than or equal to " << divider << "\n";
std::copy (itr, n+arraySize, std::ostream_iterator<int>(std::cout, " "));
}
}
int main()
{
arrayFunction(arrayN, 20, 9);
}
|