寻找最大子数组算法
C语言实现,下面给出完整代码:
#include<stdio.h>
#include<stdlib.h>
int *FindMaxCrossSubarray(int A[],int low,int mid,int high)
{
int left_sum = -99999;
int right_sum = -99999;
int sum = 0;
int i;
int *result;
result = (int *)malloc(sizeof(int)*3);
for(i = mid;i >= low ;i--)
{
sum += A[i];
if (sum > left_sum)
{
left_sum = sum;
result[0] = i;
}
}
sum = 0;
for(i = mid+1;i<=high;i++)
{
sum += A[i];
if(sum > right_sum)
{
right_sum = sum;
result[1] = i;
}
}
result[2] = (left_sum+right_sum);
return result;
}
int *FindMaximumSubarray(int A[],int low,int high)