查找的
void func(int A[],int low,int high,int& minp,int& maxp)
{
int x, y;
if (low == high)maxp = minp = A[low];
else if (low == high - 1) {
minp = min(A[low], A[high]);
maxp = max(A[low], A[high]);
}
else {
int len = (low + high) / 2;
func(A, low, len, minp, maxp);
func(A, len + 1, high, x, y);
minp = min(minp, x);
maxp = max(maxp, y);
}
}
自己写的
void func(int A[],int low,int high,int& x,int& y)
{
if (high - low <= 1) {
x = min(A[low], A[high]);
y = max(A[low], A[high]);
}
else {
int x1, y1, x2, y2;
func(A, low, (high+low) / 2, x1, y1);
func(A, (high+low) / 2 + 1, high, x2, y2);
x = min(x1, x2);
y = max(y1, y2);
//比较前后两段的最大最小值
}
}