Пример #1
0
int indexOfMin(const double a[], int n)
{
    if(n <= 0)
        return -1;
    if(n == 1)
        return n-1;
    if(a[n-1] < a[indexOfMin(a, n-1)])
    {
        return n-1;
    }
    else
    {
        return indexOfMin(a, n-1);
    }
}
Пример #2
0
  // Return the subscript of the smallest element in the array (i.e.,
  // the one whose value is <= the value of all elements).  If more
  // than one element has the same smallest value, return the smallest
  // subscript of such an element.  If the array has no elements to
  // examine, return -1.
int indexOfMin(const double a[], int n)
{
    if (n <= 0) return -1;
    if (n == 1) return 0;

    int temp = indexOfMin(a+1, n-1) + 1;
    if (a[0] > a[temp])
        return temp;
    return 0;
}