#include <iostream>
#include <vector>
#include <random>
#include <chrono>
#include <algorithm>
#include "timing.h"
#include <list>
using namespace std;
std::default_random_engine generator;


unsigned int randomInt(unsigned int n)
{
    
    std::uniform_int_distribution<int> distribution(1,n);
    return distribution(generator); 

}

void insertVector(vector<unsigned int>& vec)
{
    unsigned int n = vec.size();
    unsigned int random;

    for(unsigned int i = 0; i<n; i++)
    {
        random = randomInt(n);
        vector<unsigned int>::iterator it = lower_bound(vec.begin(), vec.end(), random);
        vec.insert(it, random);
    }

}
void insertList(list<unsigned int>& l)
{
    unsigned int n = l.size();
    unsigned int random;

    for(unsigned int i = 0; i<n; i++)
    {
        random = randomInt(n);
        list<unsigned int>::iterator it = lower_bound(l.begin(), l.end(), random);
        l.insert(it, random);
    }

}



int main()
{
    unsigned int n = 10000;
    vector<unsigned int> vec = {};
    list<unsigned int> l = {};
    for(unsigned int i=1; i<=n; i++)
    {
        vec.push_back(i);
        l.push_back(i);
    }
    tic();
    insertVector(vec);
    double vecTime = toc();

    tic();
    insertList(l);
    double listTime = toc();

    cout << is_sorted(vec.begin(), vec.end())<< endl;
    cout << is_sorted(l.begin(), l.end())<< endl;

    cout << "vector time: " << vecTime << endl;
    cout << "list time: " << listTime << endl;

    return 0;
}
