求最大子数组之和的分治算法
#include <stdio.h> #include <limits.h> typedef struct _node { int left; int right; int sum; }Node; void findCrossSubArr(int *arr,int low,int mid,int high,Node *crossResult) { int left_sum=INT_MIN; int sum=0; int i=mid; for(;i>=low;i--) { sum=sum+arr[i]; if(sum>left_sum) { left_sum=sum; crossResult->left=i; } } int right_sum=INT_MIN; sum=0; i=mid+1; for(;i<=high;i++) { sum=sum+arr[i]; if(sum>right_sum) { right_sum=sum; crossResult->right=i; } } crossResult->sum=left_sum+right_sum; } void findMaxSubArr(int *arr,int low,int high,Node *result) { if(low==high) { result->left=low; result->right=low;