本题要求实现一个函数,要求返回顺序表的最大值,空表返回0。题目保证顺序表中所有元素都为正整数。
函数接口定义:
int GetMax(SqList L);
其中SqList结构定义如下:
t
ypedef struct{
ElemType *elem;
int length;
}SqList;
裁判测试程序样例:
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 5
typedef int ElemType;
typedef struct{
ElemType *elem;
int length;
}SqList;
void InitList(SqList &L);/*细节在此不表*/
int GetMax(SqList L);
int main()
{
SqList L;
InitList(L);
int p;
p=GetMax(L);
if(p) printf("The max of SequenceList L is %d.\n",p);
else printf("The SequenceList is null.\n");
return 0;
}
/* 请在这里填写答案 */
输入格式:
输入数据有1行,首先给出以-1结束的顺序表元素(不超过100个,-1不属于顺序表元素),所有数据之间用空格分隔。题目保证输入的顺序元素都是正整数。
输入样例:
2 6 4 13 9 -1
输出样例:
The max of SequenceList L is 13.
AC代码
int GetMax(SqList L){
int i,maxx;
for(i=0;i<L.length;i++){
if(maxx<L.elem[i]){
maxx=L.elem[i];
}
}
return maxx;
}