include iostream include string using namespace std template typename

 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
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <string.h>
using namespace std;
template <typename T>
T Sort(const T *a, int size ){
T tmp;
T tmp1;
T tmp2;
for(int i = 0; i < size; i++){
if(a[i] > 0 && a[i+1] < 0){
tmp = a[i];
a[i] = a[i+1];
a[i+1] = tmp;
}
}
for(int i = 0; i < size; i++){
do{
if(a[i] < a[i+1]){
tmp1 = a[i];
a[i] = a[i+1];
a[i+1] = tmp1;
}
}while(a[i] < 0);
if(a[i] > a[i+1]){
tmp2 = a[i];
a[i] = a[i+1];
a[i+1] = tmp2;
}
}
}
void printArray(const char *a, int size)
{
for (int i = 0; i < size; i++)
cout << a[i] << " ";
cout << endl;
}
int main()
{
int N;
double с[N];
cout << "Vvedite razmer massiva: " << endl;
cin >> N;
cout << "Vvedite massiv double: " << endl;
for(int i = 0; i < N; i++)
cin >> с[N];
cout << "Poluchennyi massiv double: " << Sort<double>( с, N) << endl;
char b[] = "stdryfy";
int len = strlen(b);
cout << "Poluchennyi massiv char: " << Sort<char>( b, len) << endl;
return 0;
}