|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
请教各位大佬!!!
#include <stdio.h>
#include <stdlib.h>
struct Student
{
char name[10];
char hao[10];
int score;
struct Student *next;
}student;
void getInput(struct Student *student);
void addStudent(struct Student **student,int n);
struct Student *maxScore(struct Student *student);
struct Student *minScore(struct Student *student);
void printStudent(struct Student *student);
void getInput(struct Student *student)
{
struct Student *temp;
temp=student;
scanf("%s ",temp->name);
scanf("%s ",temp->hao);
scanf("%d",&temp->score);
}
void addStudent(struct Student **student,int n)
{
struct Student *temp;
struct Student *p;
while(n--)
{
p=(struct Student *)malloc(sizeof(struct Student));
if(p==NULL)
{
exit(1);
}
getInput(p);
if(*student!=NULL)
{
temp=*student;
*student=p;
p->next=temp;
}
else
{
*student=p;
p->next=NULL;
}
}
}
struct Student *maxScore(struct Student *student)
{
struct Student *maxScore=student;
while(student!=NULL)
{
if(student->score > maxScore->score)
{
maxScore=student;
}
student=student->next;
}
return maxScore;
}
struct Student *minScore(struct Student *student)
{
struct Student *minScore=student;
while(student!=NULL)
{
if(student->score < minScore->score)
{
minScore=student;
}
student=student->next;
}
return minScore;
}
void printStudent(struct Student *student)
{
printf("%s ",student->name);
printf("%s",student->hao);
}
int main(void)
{
struct Student *student=NULL;
struct Student *max;
struct Student *min;
int n;
scanf("%d",&n);
addStudent(&student,n);
max=maxScore(student);
min=minScore(student);
printStudent(max);
printf("\n");
printStudent(min);
return 0;
}
char name[10];
char hao[10];
空间太小
|
-
问题描述
-
为什么按照上面的输入最后会有个Y呢
|