mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-11-23 15:48:42 +00:00
26 lines
483 B
C
26 lines
483 B
C
int max(int a[], int m, int n) {
|
|
if (m == n) {
|
|
return a[m];
|
|
}
|
|
|
|
int mid = (m + n) / 2;
|
|
|
|
int left_max = max(a, m, mid);
|
|
int right_max = max(a, mid + 1, n);
|
|
|
|
return left_max > right_max ? left_max : right_max;
|
|
}
|
|
|
|
int min(int a[], int m, int n) {
|
|
if (m == n) {
|
|
return a[m];
|
|
}
|
|
|
|
int mid = (m + n) / 2;
|
|
|
|
int left_min = min(a, m, mid);
|
|
int right_min = min(a, mid + 1, n);
|
|
|
|
return left_min < right_min ? left_min : right_min;
|
|
}
|