Фикс обработки пустого вектора
Этот коммит содержится в:
@@ -1,24 +1,22 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "histogram.h"
|
||||
|
||||
//afasfaafasfaa
|
||||
using namespace std;
|
||||
|
||||
void find_minmax(const vector <double> &numbers, double &min, double &max)
|
||||
bool find_minmax(const vector <double> &numbers, double &min, double &max)
|
||||
{
|
||||
if (numbers.empty()) {
|
||||
return false;
|
||||
}
|
||||
min = numbers[0];
|
||||
max = numbers[0];
|
||||
for (double x : numbers)
|
||||
{
|
||||
if (x < min)
|
||||
{
|
||||
min = x;
|
||||
}
|
||||
else if (x > max)
|
||||
{
|
||||
max = x;
|
||||
}
|
||||
if (x < min) min = x;
|
||||
if (x > max) max = x;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
vector<size_t> make_histogram(const vector<double> &numbers, size_t bin_count)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
void find_minmax(const std::vector <double> &numbers, double &min, double &max);
|
||||
bool find_minmax(const std::vector <double> &numbers, double &min, double &max);
|
||||
|
||||
@@ -40,6 +40,10 @@
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h">
|
||||
<Option target="<{~None~}>" />
|
||||
|
||||
14
main.cpp
14
main.cpp
@@ -33,16 +33,18 @@ input_data()
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
Input in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
|
||||
double min, max;
|
||||
double bin_size = (max - min) / in.bin_count;
|
||||
// show_histogram_text(bins, in.bin_count, bin_size);
|
||||
show_histogram_svg(bins);
|
||||
//# Ïåðåìåííûå + íà÷àëî ïðîãðàììû(ââîäû)
|
||||
|
||||
double min, max;
|
||||
|
||||
double bin_size = (max - min) / in.bin_count;
|
||||
show_histogram_text(bins, in.bin_count, bin_size);
|
||||
//show_histogram_svg(bins);
|
||||
}
|
||||
// | 3 3 5 5 5 4 4 4 4 4
|
||||
|
||||
|
||||
4
text.cpp
4
text.cpp
@@ -17,7 +17,6 @@ void show_histogram_text(const vector<size_t>& bins, size_t& bin_count, double b
|
||||
max_bin_count = bins[i];
|
||||
}
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
if(bins[i]<10)
|
||||
@@ -53,6 +52,7 @@ void show_histogram_text(const vector<size_t>& bins, size_t& bin_count, double b
|
||||
{
|
||||
cout<<"*";
|
||||
}
|
||||
cout<<endl;
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user