F
Flamingo
Hi guys,
I want to write a recursion function that returns the maximum among the
first n elemetns of an array, using at most "lgn" recursive calls.
here is my function:
public class Prob0405 {
/**
* @param args
*/
public static double max(double[] a, int n)
{
if(n==1) return a[0];
int n1 = n/2;
int n2 = n-n1;
double m1 = max(a, n1);
double m2 = max(a+n1,n2);
return (m1>m2 ? m1:m2);
}
}
but when I try to compile , some syntex error reported, error happend
at "double m2 = max(a+n1,n2)",
it is said "The operator + is undefined for the argument type(s)
double[], int",
how could modify that? Any help would be appreciated! thanks.
I want to write a recursion function that returns the maximum among the
first n elemetns of an array, using at most "lgn" recursive calls.
here is my function:
public class Prob0405 {
/**
* @param args
*/
public static double max(double[] a, int n)
{
if(n==1) return a[0];
int n1 = n/2;
int n2 = n-n1;
double m1 = max(a, n1);
double m2 = max(a+n1,n2);
return (m1>m2 ? m1:m2);
}
}
but when I try to compile , some syntex error reported, error happend
at "double m2 = max(a+n1,n2)",
it is said "The operator + is undefined for the argument type(s)
double[], int",
how could modify that? Any help would be appreciated! thanks.