求助C的线性算法
struct subsequence{int value;
int start;
int end;
};
subsequence maxsubsequence(int a[],int N)
{
subsequence maxsub;
maxsub.value=0;maxsub.start=0;maxsub.end=0;
int sum=0;
for(int i=0;i<N;i++)
{
sum+=a[i];
if(sum>maxsub.value)
{maxsub.value=sum;
maxsub.end=i;
}
else if(sum<0)
{
sum=0;
if(maxsub.value==0)maxsub.start=i+1;
}
}
return maxsub;
}
这里是不是出错了if(maxsub.value==0)maxsub.start=i+1;
如果a[]={3,-5,4,9}呢?
麻烦高手帮忙一下