Text: |
ФІО = ГВА
Запитання:// Сортування. Метод бінарних вставок
#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
//=========================================================
void print_mas(int *mas,int n){
cout<<"Printmas \n\r";
for (int i = 0 ; i < n ; i++){
cout<<(*(mas+i))<<" ";
}
cout<<endl;
return ;
}
//=========================================================
void sort_mas_mbs(int *mas,int n){
int i = 2 , b , e , c , k , A ;
do
{
b = 1;
e = i - 1;
c = (b+e)/2;
while (b != c)
{
if ( *(mas+c-1) > *(mas+i-1))
{
e = c;
}
else
{
b = c;
}
c = ( b + e ) / 2;
}
if ( *(mas+b-1) < *(mas+i-1) )
{
if (*(mas+i-1) > *(mas+e-1))
{
b = e + 1;
}
else
{
b = e;
}
}
k = i;
A = *(mas+i-1);
while ( k > b )
{
*(mas+k-1) = *(mas+k-1-1);
k--;
}
*(mas+b-1) = A;
i++;
} while ( (i <= n));
return ;
}
//=========================================================
void enter_mas(int *mas,int n){
for (int i = 0 ; i < n ; i++){
cout<<"Enter mas[ "<<i<<" ] = ";
cin>>(*(mas+i));
}
return ;
}
//=========================================================
void EnterN(int &n){
do
{
cout<<" Enter N = ";
cin>>n;
bool z= (n<=1 );
if (z) { cout<<" ERROR : N>=2 !!! \n\r";}
} while (n<=1);
return ;
}
int main(){
int n;
cout<<" Metod binarnih vstavok. By Gorbachenko V.A. \n\r";
EnterN(n);
int *mas=new int[n];
enter_mas(mas,n);
print_mas(mas,n);
sort_mas_mbs(mas,n);
print_mas(mas,n);
delete []mas;
getch();
return 0;
}
====================================
|