#include <iostream>
#include <conio.h>
using namespace std;
const size_t MAX = 20;

void printArray(int *arr, size_t max) {
    for(size_t i = 0; i < max; ++i) {
        cout << " "<< arr[i] ;
    }
    cout << endl;
} // printArray

void bubbleSort(int arr[], size_t max) {
    size_t i, j;
    int t;
    size_t mov=0, vs=0;

    for(i = 1; i < max; ++i) {
        for(j = 0; j < max - i; ++j) {
            if (arr[j] > arr[j+1]) {
                t = arr[j]; arr[j] = arr[j+1]; arr[j+1] = t;
                mov+=3;
            } vs++;
        }
    }
  cout<< "\n\tbubbleSort: vs = "<< vs <<"; mov = "<< mov <<";\n";
  printArray(arr, max);

} // bubbleSort

void insert (size_t n, int x[])
{
 int j, t;
 size_t i,  mov=0, vs=0;

 for (i=0; i<n; i++)
 {
   t = x[i];
   mov++;
   for (j=i-1; j>=0 && vs++ && x[j]>t; j--)
   {
     x[j+1]=x[j];
     mov++;
   }
   x[j+1]=t;
   mov++;
 }
 cout<< "\n\tinsert: vs = "<< vs <<"; mov = "<< mov <<";\n";
  printArray(x, n);
}// insert

int main() {
    size_t emax=0, i;
while(1){
  cout<<"Enter the number of elements (2<n<"<< MAX <<"): ";
  cin>>emax;
if (emax>2 && emax < MAX) break;
}
int *arr = new int[emax];
int *aOut = new int[emax];

cout <<"\n\nEnter the elements now :\n\t";
for (i = 0; i < emax; i++) cin>>arr[i];
/*  копирование */
for (i = 0; i < emax; i++) aOut[i] = arr[i];

bubbleSort(aOut, emax);
insert(emax, arr);
delete arr;
delete aOut;

getch();
return 0;
}