Closed alexey-malov closed 5 years ago
double MinElementVector(vector<double> const& v)
{
if (v.empty())
{
return NULL;
}
else
{
return *min_element(v.begin(), v.end());
}
}
void ProcessVector(vector<double> &v)
{
double min = MinElementVector(v);
if (!min)
{
return;
}
for (size_t i = 0; i < v.size(); i++)
{
v[i] *= min;
}
}
[x] Если минимальный элемент вектора равен 0, то массив обработан не будет. Написать тест, воспроизводящий эту ситуацию. Он не должен проходить. Потом исправить программу, чтобы тест проходил
[x] Старайтесь избегать сырых циклов. Отдавайте предпочтение алгоритмам стандартной библиотки (в вашем случае - transform), либо вместо итерирования по индексам используйте range-based версию for:
for (auto& item : v)
{
item *= v;
}