#include "histogram.h"
using namespace std;

void FindMinMax(const vector<double>& marks, double& min, double& max) {
    max = 0;
    if (marks.size() != 0) {
        min = marks[0];
        for (double x : marks) {
            if (x > max) {
                max = x;
            }
            if (x < min) {
                min = x;
            }
        }
    }else{ min = 0; }
}


vector <double> MakeHistogram(const vector<double>& marks, int NCharts) {
    double interval = 0, i = 0, min = 0, max = 0;
    vector<double> chart(NCharts);
    FindMinMax(marks, min, max);
    interval = (max - min) / NCharts;
    for (int x : marks) {
        i = 0;
        while ((x > min + interval * (i + 1))) {
            i += 1;
        }
        chart[i] += 1;
    }
    return chart;
}