6-5 求自定类型元素的最大值

本题要求实现一个函数,求N个集合元素S[]中的最大值,其中集合元素的类型为自定义的ElementType。

原题地址

 ElementType Max( ElementType S[], int N )
{
    int i;
    ElementType a=S[0];
    for(i=1;i<N;i++)
    {
        if(S[i]>a)
        {
            a=S[i];
        } 

    }
    return a;
}

problem:
for循环中为何 i < N,S[N]不用判断吗?
i为何从1开始

猜你喜欢

转载自blog.csdn.net/qq_42825058/article/details/82698375