* main.c
* 使用分治法求数组的最大值
* Created on: Nov 7, 2010
* Author: jenson
*/
#include <stdio.h>
typedef int item_type;
item_type max(item_type a[], int l, int r);
int main() {
item_type a[] = { 1, 4, 8, 0, 5, 8, 9, -1 };
int result = max(a,0,8);
printf("max=%d",result);
return 0;
}
item_type max(item_type a[], int l, int r) {
item_type u, v;
int m = (l + r) / 2;
if (l == r) {
return a[l];
}
u = max(a, l, m);
v = max(a, m + 1, r);
return (u > v ? u : v);
}