// .
// .
#include<iostream.h>
#include <locale.h>
//using namespace std;
const int RAZ = 10; //
typedef int telem; //
typedef telem tmas[RAZ]; //
void outputmas(tmas a, int n); //
void sort_obmen(tmas a, int n); //
void sort_obmenF(tmas a, int n); //
void sort_vibor(tmas a, int n); //
void sort_vstav(tmas a, int n); //
void sort_quick(tmas a, int t, int n); //
int main()
{tmas mas_a = {10,9,8,7,6,5,4,3,2,1}; //
tmas mas_b = {19,17,15,13,11,9,7,5,3,1}; // b
tmas mas_c = {20,18,16,14,12,10,8,6,4,2}; // c
tmas mas_d = {1,10,2,9,3,8,4,7,5,6}; // e
tmas mas_e = {2,9,4,10,7,1,6,5,3,8}; // f
int n;
setlocale(LC_ALL,"Russian");
cout << " " << endl;
cout << " : " << endl;
outputmas(mas_a, RAZ);
cout << "\n ( ):" << endl;
sort_obmen(mas_a, RAZ);
outputmas(mas_a, RAZ);
cout << "\n b: " << endl;
outputmas(mas_b, RAZ);
cout<<"\n b ( ):" <<endl;
sort_obmenF(mas_b, RAZ);
outputmas(mas_b, RAZ);
cout << "\n c: " << endl;
outputmas(mas_c, RAZ);
cout<<"\n c ( ):" <<endl;
sort_vibor(mas_c, RAZ);
outputmas(mas_c, RAZ);
cout << "\n d: " << endl;
outputmas(mas_d, RAZ);
cout << "\n d ( ):" << endl;
sort_vstav(mas_d, RAZ);
outputmas(mas_d, RAZ);
cout << "\n e: " << endl;
outputmas(mas_e, RAZ);
cout<<"\n e ( ):"<<endl;
sort_quick(mas_e, 0, RAZ - 1);
outputmas(mas_e, RAZ);
return 0;
}
//
void sort_obmen(tmas a, int n)
{ int i, k;
telem z;
for(k = n; k > 0; k--)
for(i = 0; i < k - 1; i++)
if(a[i] > a[i + 1])
{z = a[i];
a[i] = a[i + 1];
a[i + 1] = z;
}
}
//
void sort_obmenF(tmas a, int n)
{ int i, k, flag;
telem z;
k = n; //
do{flag = 0;
for(i = 0; i < k - 1; i++)
if(a[i] > a[i + 1])
{z = a[i];
a[i] = a[i + 1];
a[i + 1] = z;
flag = 1;
}
k--;
}while(flag);
|
|
}
//
void sort_vibor(tmas a, int n)
{ int i, k, imin;
telem z;
for(i = 0; i < n - 1; i++)
{imin = i; //
for(k = i + 1; k < n; k++)
if(a[k] < a[imin]) imin = k;
//
z = a[i];
a[i] = a[imin];
a[imin] = z;
}
}
//
void sort_vstav(tmas a, int n)
{ int i, j, k;
telem z;
for(i = 1; i < n; i++)
{z = a[i]; //
j = 0;
//
while(j < i && a[j] <= a[i]) j++;
for(k = i - 1; k >= j; k--)
a[k + 1] = a[k]; //
a[j] = z;
}
}
//
void sort_quick(tmas a, int t, int n)
{ int i = t, //
j = n; //
telem x, y;
x = a[(t + n) / 2];
do{
while(a[i] < x) i++;
while(x < a[j]) j--;
if(i <= j)
{y = a[i];
a[i] = a[j];
a[j] = y;
i++;
j--;
}
}while(i < j);
if(t < j) sort_quick(a, t, j);
if(i < n) sort_quick(a, i, n);
}
void outputmas(tmas a, int n)
{for(int i = 0; i < n; i++)
cout << a[i] << ' ';
}