bool g_InvalidInput=false;//判断输入是否有效
int findGreatestSumOfSubArray(int *pData,int length){
if((pData==null)||(length<=0)){
g_InvalidInput=true;
return 0;
}
g_InvalidInput=false;
int CurSum=0;
int GreatestSum=0x80000000;
for(int i=0;i<length;i++){
if(CurSum<=0){
CurSum=pData[i];
}else
{
CurSum+=pData[i];
}
if(CurSum>GreatestSum){
GreatestSum=CurSum;
}
}
return GreatestSum;
}//求一个整数数组中的所有子数组和的最大值
int findGreatestSumOfSubArray(int *pData,int length){
if((pData==null)||(length<=0)){
g_InvalidInput=true;
return 0;
}
g_InvalidInput=false;
int CurSum=0;
int GreatestSum=0x80000000;
for(int i=0;i<length;i++){
if(CurSum<=0){
CurSum=pData[i];
}else
{
CurSum+=pData[i];
}
if(CurSum>GreatestSum){
GreatestSum=CurSum;
}
}
return GreatestSum;
}//求一个整数数组中的所有子数组和的最大值