here is a better way of doing this because your code would not compile
[ #include <iostream> #include <array> #include <string> using namespace std; template<typename T> T maxValue(T list[],const int& size) { T currentMax = list[0];
for (int i = 0; i < size; i++) {
if(currentMax < list[i]) { currentMax = list[i]; } } return currentMax; }
int main() { int intArray[] = { 1, 2, 4, 2, 5, 3, 1 }; cout << "Max int value is " << maxValue(intArray, 7) << endl;
double doubleArray[] = { 1.4, 2, 0.4, 2, 0.5, 3, 1 }; cout << "Max double is " << maxValue(doubleArray, 7) << endl;
string strings[] = { "abc", "cbs", "nbc" };
cout << "Max string is " << maxValue(strings, 3) << endl;
return 0; } ] |