最大字数组求解:请大家帮我纠正错误
void Max_Cross_Array(int num[],int low,int high,int * index_l,int * index_h,int * sum){
int mid=(low+high)/2;//mid
int l_max,r_max,temp;//最大值存储,当前值存储
int l,r,l_low,r_high;
l_low=mid;//左侧保存点
r_high=mid+1;//右侧保存
for(l=mid,l_max=0,temp=0;l>=low;l--)
{
temp+=num[l];
if(temp>=l_max)
{
l_max=temp;
l_low=l;
}
}
for(r=mid+1,r_max=0,temp=0;r<=high;r++)
{
temp+=num[r];
if(temp>=r_max)
{
r_max=temp;
r_high=r;
}
}
*index_l=l_low;
*index_h=r_high;
*sum=l_max+r_max;
}
void Max_Subarray (int * A,int * low,int * high,int * sum)
{
printf("%d ",count++);
if(*low==*high)
*sum=A[*low];
else{
int mid=(*low+*high)/2;
int l,r;
l=*low;r=*high;
*low=l;*high=mid;
Max_Subarray(A,low,high,sum);
left_low=*low;
left_high=*high;
left_sum=*sum;
*low=mid+1;
*high=r;
right_low=*low;
right_high=*high;
right_sum=*sum;
*low=l;
*high=r;
Max_Cross_Array(A,*low,*high,low,high,sum);
cross_low=*low;
cross_high=*high;
cross_sum=*sum;
if(cross_sum>=right_sum&&cross_sum>=left_sum)
{
*low=left_low;
*high=left_high;
*sum=left_sum;
}
else if(right_sum>=left_sum&&right_sum>=cross_sum)
{
*low=right_low;
*high=right_high;
*sum=right_sum;
}
else
{
*low=left_low;
*high=left_high;
*sum=left_sum;
}
}
}
这是两个函数的代码。