#include "cmath"
#include <chrono>
#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
#include <cstdlib>

using namespace std::chrono;

int RandomNumber2() { return (std::rand() % 100); }
void FillVector(std::vector<int>& a) {
    std::srand(unsigned(std::time(0)));
    std::generate(a.begin(), a.end(), RandomNumber2);
    std::cout << "\n\nVector: ";
    for (std::vector<int>::iterator it = a.begin(); it != a.end(); it++) std::cout << *it << " ";
}

void CocktailSort(std::vector<int>& a, int n) {
	   bool flag = true;
   int start = 0, end = n-1;
   while(flag){
      flag = false;
      for(int i = start; i<end; i++){
         if(a[i] > a[i+1]){
            std::swap(a[i], a[i+1]);
            flag = true;
         }
      }
      if(!flag){
         break;
      }
      flag = false;
      end--;
      for(int i = end - 1; i >= start; i--){
         if(a[i] > a[i+1]){
            std::swap(a[i], a[i+1]);
            flag = true;
         }
      }
      start++;
   }
}

double measureTime(std::vector<int>& a, int n) {
    steady_clock::time_point t1 = steady_clock::now();
    CocktailSort(a, n);
    steady_clock::time_point t2 = steady_clock::now();
    duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
    double mTime = time_span.count();
    std::cout <<  mTime << std::endl;
    return mTime;
}


void Experiment(std::vector<int> &a, int n) {
    FillVector(a);
    CocktailSort(a, n);
    std::cout << "\n\na. Sorted data: ";
    for (int i{ 0 }; i < n; i++) std::cout << a[i] <<  ' ';

    double* times = new double[1000];
 
    for (int i=100; i < 1000; i += 100) {
        std::cout << "\n[" << i << "]" << " ";
        for (int j{1}; j < 10; j+=1) {
            times[j] = measureTime(a, i);
        }
    }
}

int main() {
    int n{1000};
    std::vector<int> a(n);
    Experiment(a, n);

    return 0;
}