#include "histogram.h"
#include "histogram_internal.h"
#include <iostream>
#include <vector>
using namespace std;

void find_minmax(const vector <double>& mas, double& min, double& max)
{
    for (size_t i = 0; i < mas.size(); i++)
    {
        if (max < mas[i])
            max = mas[i];
        if (min > mas[i])
            min = mas[i];
    }
}
vector<int> make_histogram(const vector<double>& mas, size_t bin_count)
{
    size_t i;
    vector<int> ch(bin_count);
    double max = mas[0], min = mas[0], le, ri;
    find_minmax(mas, min, max);
    le = min;
    ri = le + (max - min) / bin_count;
    int kol = 0;
    while (kol < bin_count - 1)
    {
        for (i = 0; i < mas.size(); i++)
        {
            if (le <= mas[i] && ri > mas[i])
                ch[kol]++;
        }
        kol++;
        le = ri;
        ri = le + (max - min) / bin_count;
    }
    for (i = 0; i < mas.size(); i++)
    {
        if ((ri <= mas[i] && le < mas[i]) || (le <= mas[i] && ri > mas[i]))
            ch[kol] ++;
    }
    return ch;
}