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
|
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
const int NUM_ELEMS = 7;
int a[NUM_ELEMS] = { 1, 2, 3, 4, 5, 6, 7 };
int b[NUM_ELEMS] = {10, 8, 6, 4, 2, 0, -2 };
int c[NUM_ELEMS * 2] = {0};
for (int i = 0; i < NUM_ELEMS; i++)
{
c[i] = a[i];
}
for (int i = NUM_ELEMS, j=0; i < NUM_ELEMS * 2; i++, j++)
{
c[i] = b[j];
}
cout <<"\nArray c unsorted: ";
for (int i = 0; i < NUM_ELEMS * 2; i++)
{
cout << c[i] << " ";
}
cout << "\n\n";
std::sort(c, c + NUM_ELEMS * 2, greater<int>());
cout <<"\nArray c sorted: ";
for (int i = 0; i < NUM_ELEMS * 2; i++)
{
cout << c[i] << " ";
}
cout << "\n\n";
system("pause");
return 0;
}
|