MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / largest

Function largest

Exercises/Modules/Chapter 09/Soln9_03.cpp:67–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65}
66
67std::optional<double> largest(std::span<const double> data)
68{
69 if (data.empty()) return {}; // There is no largest in an empty array
70
71 size_t index_max {};
72 for (size_t i {1}; i < data.size(); ++i)
73 if (data[index_max] < data[i])
74 index_max = i;
75
76 return data[index_max];
77}
78
79std::span<double> scale_range(std::span<double> data, double divisor)
80{

Callers 1

normalize_rangeFunction · 0.70

Calls 2

emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected