Can someone show me the code to do the opposite so it takes gets the largest of index of an array.
Having a little bit of trouble.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
template<typename BaseType>
int indexOfSmallest(const BaseType list[], int startIndex, int endIndex)
{
if (startIndex < 0 || startIndex > endIndex)
return - 1;
int indexOfMin = startIndex;
for (int index = startIndex + 1; index < endIndex; index++)
if (list[index] < list[indexOfMin])
{
indexOfMin = index;
//indexOfmin is the index of the smallest item of
// list[startIndex] through list[index]
}
return indexOfMin;
}