ElementType Max( ElementType S[], int N )
{
ElementType t,max=S[0];
int i;
for(i=1;i<N;i++)
{
if(max<S[i])
{
t=S[i];
S[i]=max;
max=t;
}
}
return max;
}
你这里的if语句是用来交换的吧?不是用来查找最大值的。
而且你先是S[i]>S[i+1]然后又让max=更小的[i+1]而不是i
能说说你的目的吗?是不是查找数组最大值?
如果对你有帮助,还请点个采纳,万分感谢!
修改如下,供参考:
ElementType Max(ElementType s[], int N)
{
ElementType max=s[0];
int i;
for(i=0;i<N;i++)
if(a[i] > max) max = s[i];
return max;
}