void FindMaxSubArray::BruteForcen3()
{
int i,j,k=0,c=0,s=0,as=-9999,l,h,N=n;
for(i=0;i<n;i++)
{
for(j=0;j<N;j++)
{
for(k=j;k<=(j+c);k++)
s+=A[k];
if(s>as)
{
as=s;
l=j+1;
h=k;
}
s=0;
}
N--;
c++;
}
cout << endl << "The Maximum SubArray of A[] is from " <<
l << " to " << h <<" and it is " << as << endl;
}
This one's working correct. Now here's the other one:
void FindMaxSubArray::BruteForcen3v2()
{
int i=0,j=0,k=0,as=-9999,s=0,l=0,h=0;
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
for(k=i;k<=j;k++)
s=+A[k];
if(s>as)
{
as=s;
l=i+1;
h=k;
}
s=0;
}
}
cout << endl << "The Maximum SubArray of A[] is from " <<
l << " to " << h <<" and it is " << as << endl;
}
Now this one isn't working correct and I can't seem to understand why. Yeah I know that there are better algorithms for finding the maximum sub array but I was getting started on this thing. Can anyone help me ?