Closed alexey-malov closed 5 years ago
template <typename T> bool FindMax(std::vector<T> const& arr, T& maxValue) { if (arr.empty()) { return false; } auto maxElement = arr[0]; for (auto currentElement : arr) { if (maxElement < currentElement) { maxElement = currentElement; } } maxValue = maxElement; return true; }
[x] Перебирать элементы массива по ссылке
[x] Копировать только один раз. Хранить указатель, итератор или индекс на текущего победителя
[x] Перебирать элементы массива по ссылке
[x] Копировать только один раз. Хранить указатель, итератор или индекс на текущего победителя