예제 #1
0
  // Return the subscript of the first element in the array for which
  // the somePredicate function returns true.  If there is no such
  // element, return -1.
int firstTrue(const double a[], int n)
{
    if (n <= 0)
    	return -1;

    int temp = firstTrue(a, n-1);
    if (somePredicate(a[n-1]) && temp == -1)
		    return n-1;
	  return temp;
}
예제 #2
0
파일: linear.cpp 프로젝트: dannyolaugh/CS32
int firstTrue(const double a[], int n)
{
    int positionHolder = n-1;  //im returning the last negative number
    if(n > 0)
    {
        if(somePredicate(a[positionHolder]))
        {
            if(n == 1)
                return positionHolder;
            else if (firstTrue(a,n-1)== -1)
                return positionHolder;
            else
                return firstTrue(a, n-1);
        }
        else
            return firstTrue(a, n-1);
        
    }
    return -1;
}