#include <stdio.h>
struct BestValue {
int min;
int max;
};
struct BestValue findMinMax(int arr[], int low, int high) {
struct BestValue result, left, right, mid;
int midIndex;
if (low == high) {
result.min = arr[low];
result.max = arr[low];
return result;
}
if (high == low + 1) {
if (arr[low] < arr[high]) {
result.min = arr[low];
result.max = arr[high];
} else {
result.min = arr[high];
result.max = arr[low];
}
return result;
}
midIndex = (low + high) / 2;
left = findMinMax(arr, low, midIndex);
right = findMinMax(arr, midIndex + 1, high);
if (left.min < right.min) {
result.min = left.min;
} else {
result.min = right.min;
}
if (left.max > right.max) {
result.max = left.max;
} else {
result.max = right.max;
}
return result;
}
int main() {
int arr[] = {5, 8, 3, 9, 1, 6, 2, 7, 4};
int n = sizeof(arr) / sizeof(arr[0]);
struct BestValue result = findMinMax(arr, 0, n - 1);
printf("Minimum value: %d\n", result.min);
printf("Maximum value: %d\n", result.max);
return 0;
}