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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
void copy_list(int to[], int from[], int size)
{
for(int i = 0; i < size; ++i)
{
to[i] = from[i];
}
}
void print_list(int list[], int size)
{
for(int i = 0; i < size; ++i)
{
std::cout << list[i];
}
}
int split (int a[], int n)
{
int size1 = n / 2;
int size2 = n - size1;
int * list1 = new int[size1];
int * list2 = new int[size2];
copy_list(list1, a, size1);
copy_list(list2, a + size1, size2);
print_list(list1, size1);
std::cout << " ";
print_list(list2, size2);
std::cout << std::endl;
delete[] list2;
delete[] list1;
return 0;
}
int main()
{
int l[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
split(l, sizeof(l) / sizeof(*l));
}
|