对了,谁能帮我改改这个程序,也是同样的问题!!
程序代码:
#include <stdio.h>
#include <stdlib.h>
struct student
{
char name[8];
float high;
long int weight;
struct student *next;
};
int n,i;
struct student *creat()//创建链表
{
i=1;
struct student *p,*head,*stud;
head=NULL;
stud=p=(struct student *)malloc(sizeof(struct student));
printf("请输入学生 %d 的身高体重姓名:",i);
scanf("%f%ld%s",&stud->high,&stud->weight,stud->name);
fflush(stdin);
while(stud->high!=0) //以学生的身高来判断循环
{
n++;
if(n==1)
{
head=stud;
head->next=NULL;
}
else
p->next=stud;
p=stud;
stud=(struct student *)malloc(sizeof(struct student));
printf("请输入学生 %d 的姓名身高体重:",++i);
scanf("%f%ld%s",&stud->high,&stud->weight,stud->name);
fflush(stdin);
}
p->next=NULL;
return(head);
}
struct student * search(struct student *head)//找出高度最高的那个学生
{
struct student *p,*q,*t;
t=p=head;
if(head!=NULL)
do
{
if(t->high<p->high)
{
q=p;
}
p=p->next;
}while(p!=NULL);
return q;
}
struct student * find(struct student *head)//找出体重最重的那个学生
{
struct student *p,*q,*t;
t=p=head;
if(head!=NULL)
do
{
if(t->weight<p->weight)
{
q=p;
}
p=p->next;
}while(p!=NULL);
return q;
}
void main(void)
{
struct student *p,*q,*head;
head=creat();
p=search(head);
printf("%s%f%ld",p->high,p->weight,p->name);
q=find(head);
printf("%s%f%ld",q->high,q->weight,q->name);
}