#define _CRT_NO_SECURE_WARNINGS
#include<stdio.h>
#include<iostream>
using namespace std;
int str[2] = { 0 };
int* MAXMIN(int i, int j, int* a) {
int max = 0;
int min = 0;
int mid = 0;
int lmax = 0;
int lmin = 0;
int rmax = 0;
int rmin = 0;
int* ltem;
int* rtem;
if (i == j) {
max = a[i];
str[0] = max;
min = a[i];
str[1] = min;
}
else if (i == j - 1) {
if (a[i] < a[j]) {
max = a[j];
str[0] = max;
min = a[i];
str[1] = min;
}
else {
max = a[i];
str[0] = max;
min = a[j];
str[1] = min;
}
}
else {
mid = (i + j) / 2;
ltem = MAXMIN(i, mid, a);
lmax = *ltem;
lmin = *(ltem + 1);
rtem = MAXMIN(mid + 1, j, a);
rmax = *rtem;
rmin = *(rtem + 1);
if (lmax > rmax) {
max = lmax;
str[0] = max;
}
else {
max = rmax;
str[0] = max;
}
if (lmin > rmin) {
min = rmin;
str[1] = min;
}
else {
min = lmin;
str[1] = min;
}
}
return str;
}
int main() {
int a[100] = { 0 };
int j = 0;
int k = 0;
int* p;
char c ='0';
cout << "请输入要求最大最小值的数列:"<<endl;
for (j = 0;j < 100;j++) {
cin >> a[j];
if (getchar() == '\n') {
break;
}
}
p=MAXMIN(0, j, a);
cout << "此序列最大值为:" << *p << endl;
cout << "此序列最小值为:" << *(p + 1) << endl;
system("pause");
return 0;
}