upd:Код откачен до момента защиты

main
PARZIVAL (BreganIM) 1 месяц назад
Родитель 07c73e5335
Сommit d5f702afa3

@ -1,13 +1,13 @@
#include "histogram.h"
#include "histogram_internal.h"
#include <iostream>
#include <vector>
using namespace std;
bool find_minmax(const vector<double>& numbers, double& min, double& max) {
if (numbers.empty())
if (numbers.empty()) {
return false;
}
min = numbers[0];
max = numbers[0];
for (double x : numbers) {
@ -16,7 +16,7 @@ bool find_minmax(const vector<double>& numbers, double& min, double& max) {
if (x > max)
max = x;
}
return true;
return false;
}
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
@ -27,6 +27,7 @@ vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
for (size_t i = 0; i < numbers.size(); i++) {
bool found = false;
for (size_t j = 0; j < bin_count - 1 && !found; j++) {
double lo = min + j * bin_size;
double hi = min + (j + 1) * bin_size;
@ -35,15 +36,9 @@ vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
found = true;
}
}
if (!found)
bins[bin_count - 1]++;
}
return bins;
}
double compute_bin_size(const std::vector<double>& numbers, size_t bin_count) {
double min, max;
if (!find_minmax(numbers, min, max))
return 0.0;
return (max - min) / bin_count;
}

Загрузка…
Отмена
Сохранить