diff --git a/main.cpp b/main.cpp index 473cf83..2ee71a0 100644 --- a/main.cpp +++ b/main.cpp @@ -20,7 +20,7 @@ input_data(){ cin >> in.bin_count; return in; } - void find_minmax(vector numbers, double& min, double& max) { + void find_minmax(const vector& numbers, double& min, double& max) { min = numbers[0]; max = numbers[0]; for (double x : numbers) { @@ -32,18 +32,15 @@ return in; } } } - - -int main() -{ Input in = input_data(); +vector make_histogram(const vector& numbers,size_t bin_count){ double max,min; - find_minmax(in.numbers,min,max); - double bin_size = (max - min) / in.bin_count; - vector bins(in.bin_count); - for(double x:in.numbers) + find_minmax(numbers,min,max); + double bin_size = (max - min) / bin_count; + vector bins(bin_count); + for(double x:numbers) { bool found = false; - for (size_t j = 0; (j < in.bin_count - 1) && !found; j++) { + for (size_t j = 0; (j < bin_count - 1) && !found; j++) { auto lo = min + j * bin_size; auto hi = min + (j + 1) * bin_size; if ((lo <= x) && (x < hi)) { @@ -52,12 +49,21 @@ int main() } } if (!found) - bins[in.bin_count-1]++; + bins[bin_count-1]++; } - for(size_t i=0;i bins,size_t bin_count){ + for(size_t i=0;i