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
46
47
48
49
50
51
52
| #include <iostream>
#include <ctime>
#include <algorithm>
#include <iterator>
template<class T>void sort(int* mas, int low, int N)
{
int i = low;
int j = N;
int pivot = mas[(low + N) / 2];
for(i, j; i <= j;)
{
while(mas[i] > pivot)
i++;
while(mas[j] < pivot)
j--;
if(i <= j)
std::swap(mas[i++], mas[j--]);
}
if(i < N)
sort<T>(mas, i, N);
if(j > low)
sort<T>(mas, low, j);
}
int main()
{
int n;
int max = 0, min = 0;
std::cin >> n;
int* mas = new int[n];
srand(time(0));
for(int i = 0; i < n; i++)
mas[i] = rand()%40;
std::copy(mas, mas + n, std::ostream_iterator<int>(std::cout, "\t"));
std::cout << std::endl;
for(int i = 1; i < n; i++)
if(mas[max] < mas[i])
max = i;
std::cout << "max - " << mas[max] << std::endl;
for(int i = 0; i < n; i++)
mas[i] += mas[max];
for(int i = 1; i < n; i++)
if(mas[min] >= mas[i])
min = i;
std::cout << "min - " << mas[min] << std::endl;
sort<int>(mas, 0, n - 1);
std::copy(mas, mas + n, std::ostream_iterator<int>(std::cout, "\t"));
system("pause");
return 0;
} |