# 一道很简单的题目--不同的写法

First 比较简单的写法，直接比较大小，不保存数据

```int main()
{
int  max = 0, sou;
while (1)
{
printf("输入成绩\n");
scanf("%d", &sou);
if (max < sou)
{
max = sou;
}
if (sou < 0)
{
break;
}
}
printf("最大值是%d", max);
return 0;
}```

2.不需要的东西不用传入链表，尤其是输入结束的标志位

3.释放链表和定义的动态数组

```struct Node
{
int a;
struct Node* pNEXT;
};
struct Node* g_pEnd = NULL;

struct Node* Create_Node(int N)
{
struct Node* pTemp = (struct Node*)malloc(sizeof(struct  Node));
pTemp->a = N;
pTemp->pNEXT = NULL;
return pTemp;
}

//尾添加
{
struct Node* pTemp = Create_Node(N);
{
g_pEnd = pTemp;
}
else
{
g_pEnd->pNEXT = pTemp;
g_pEnd = pTemp;
}
}

{
struct Node* CANSHU = TouPlace;
while (CANSHU != NULL)
{
struct Node* pt = CANSHU;            //构建中间参数
CANSHU = CANSHU->pNEXT;                //先指向下一个，再释放
free(pt);                            //释放内存
}
g_pEnd = NULL;
}

int main()
{
int a;
int max = 0;
int n=0;
int m = 0;
int *G;
int p = 0;

while (1)
{
printf("请输入数据\n");
scanf("%d", &a);

if (a < 0)
{
printf("数据输入完毕");
break;
}
}
while (Tplace != NULL)
{
n++;
Tplace = Tplace->pNEXT;
}
printf("人数为%d\n", n);

G =(int*)malloc(n*sizeof(int));
while (Tplace2 != NULL)
{
G[p]= Tplace2->a;
if (max < G[p])
{
max = G[p];
}
p++;
Tplace2 = Tplace2->pNEXT;
}
//释放G的空间
free(G);

//释放链表
List_Free_All(Tplace2);
printf("最高的成绩是%d", max);
return 0;
}```

(0)
(0)