有人可以告诉我我做错了什么吗?我编写了这个最小和最大查找器,但我不断收到此错误:“我的”mml = getMinMax(a,低,高)“StackOverflowError”。任何帮助将不胜感激。谢谢!
public class MinMax {
int min;
int max;
public static void main(String[] args){
int a[] = {4, 23, 6, 42, 11};
int aSize = a.length -1;
MinMax test = getMinMax(a,0,aSize);
System.out.println("Minimum: " + test.min);
}
public static MinMax getMinMax(int a[], int low, int high){
MinMax minmax = new MinMax();
MinMax mml = new MinMax();
MinMax mmr = new MinMax();
int mid = ((low + high)/2);
mml = getMinMax(a, low, mid);
mmr = getMinMax(a, mid+1, high);
if(mml.min < mmr.min){
minmax.min = mml.min;
}else{
minmax.max = mmr.max;
}
if(mml.max > mmr.max){
minmax.max = mml.max;
}else{
minmax.max = mmr.max;
}
return minmax;
}
}