main
Родитель
413a3053b9
Сommit
9fdfc9c49b
@ -0,0 +1,59 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include "histogram.h"
|
||||||
|
|
||||||
|
//std::vector<size_t>
|
||||||
|
|
||||||
|
bool
|
||||||
|
find_minmax(const std::vector<double> numbers, double& min, double& max)
|
||||||
|
{
|
||||||
|
if(numbers.empty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/*/double/*/ min = numbers[0];//ïîèñê ìèí è ìàêñ
|
||||||
|
/*/ double/*/ max = numbers[0];
|
||||||
|
for (double x : numbers)
|
||||||
|
{
|
||||||
|
if (x < min)
|
||||||
|
{
|
||||||
|
min = x;
|
||||||
|
}
|
||||||
|
else if (x > max)
|
||||||
|
{
|
||||||
|
max = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<size_t>
|
||||||
|
make_histogram(const std::vector<double> numbers, size_t bin_count)
|
||||||
|
{
|
||||||
|
std::vector <size_t> bins(bin_count);
|
||||||
|
double min, max;
|
||||||
|
find_minmax(numbers, min, max);
|
||||||
|
double bin_size = (max-min)/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++)
|
||||||
|
{
|
||||||
|
auto lo = min + j * bin_size;
|
||||||
|
auto hi = min + (j + 1) * bin_size;
|
||||||
|
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
||||||
|
{
|
||||||
|
bins[j]++;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
bins[bin_count - 1]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bins;
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_layout_file>
|
||||||
|
<FileVersion major="1" minor="0" />
|
||||||
|
<ActiveTarget name="Debug" />
|
||||||
|
<File name="histogram_internal.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="205" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="unittest.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="1016" topLine="1" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="doctest.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="112412" topLine="2358" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
</CodeBlocks_layout_file>
|
||||||
Загрузка…
Ссылка в новой задаче