#include "bsp_1_e.h"
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <ctime>

using namespace std;

vector<int> sortvec(const vector<int> &x, const vector<int> &y)
{
    vector<int> result = x;
    for(size_t k = 0; k<y.size(); ++k)
    {
        auto pos = lower_bound(result.begin(), result.end(), y[k]);
        result.insert(pos, y[k]);
    }
    // check if sorted
    if(is_sorted(result.begin(), result.end()) == 0)
    {
        cout << "FEHLER - nicht sortiert" << endl;
    }

    return result;
}


vector<int> genrandvec(const int &n)
{
    vector<int> v;
    srand((unsigned) time(NULL));
    for(int k=0; k<n; ++k)
    {
        int random = 1 + (rand() % n);
        v.push_back(random);
    }

    return v;
}


vector<int> gensortvec(const int & n)
{
    vector<int> v;
    for(int k = 0; k<n; ++k)
    {
        v.push_back(k+1);
    }

    return v;
}



list<int> sortlist(const list<int> &x, const list<int> &y)
{
    list<int> result = x;
    for(auto it = y.begin(); it != y.end(); ++it)
    {
        auto pos = lower_bound(result.begin(), result.end(), *it);
        result.insert(pos, *it);
    }
    // check if sorted
    if(is_sorted(result.begin(), result.end()) == 0)
    {
        cout << "FEHLER - nicht sortiert" << endl;
    }

    return result;
}


list<int> genrandlist(const int &n)
{
    list<int> v;
    srand((unsigned) time(NULL));
    for(int k=0; k<n; ++k)
    {
        int random = 1 + (rand() % n);
        v.push_back(random);
    }

    return v;
}


list<int> gensortlist(const int & n)
{
    list<int> v;
    for(int k = 0; k<n; ++k)
    {
        v.push_back(k+1);
    }

    return v;
}


list<int> genlistfromvec(const vector<int> &v)
{
    list<int> a;
    for(size_t k=0; k<v.size(); ++k)
    {
        a.push_back(v[k]);
    }

    return a;
}
