int GetSmallestIndex( constint* numArray, int min, int max )
{
int index = min;
for( int i = min + 1; i <= max; ++i )
{
if ( numArray[i] < numArray[index] ) index = i;
}
return index;
}
int GetSmallestIndex(int* numArray,int min,int max)
{
int smallest=numArray[0];
int index;
for(int i=min;i<=max;++i)
{
if(numArray[i]<smallest)
{
smallest=numArray[i];
index=i;
}
elsecontinue;
}
return index;
}
you set the smallest initially to numArray[0]. It iis incorrect because you have to find the smallest among elements of the array in the range numArray[min] and numArray[max]. Also the initial value of index is undefined. So when the zero alement is the smallest in the whole array the function will always return the undefined index because it will assume that the zero element is the smallest.