#include
#include
#include
struct student
{ char name[20];
char sex;
struct
{ int year;
int month;
int day;
}birth;
struct student *next;
};
struct student * compare(struct student x,struct student y);
struct student * findOldest(struct student * p);
void main()
{
struct student *a1,*a2,*a3,*a4,*temp;
a1=( struct student*)malloc(sizeof(struct student));
a2=( struct student*)malloc(sizeof(struct student));
a3=( struct student*)malloc(sizeof(struct student));
a4=( struct student*)malloc(sizeof(struct student));
a1->name[0]='a';
a1->name[1]='1';
a1->name[2]='\0';
a1->birth.day=16;
a1->birth.month=12;
a1->birth.year=1997;
a1->sex='W';
a1->next=a2;
a2->name[0]='a';
a2->name[1]='2';
a2->name[2]='\0';
a2->birth.day=23;
a2->birth.month=10;
a2->birth.year=1995;
a2->sex='M';
a2->next=a3;
a3->name[0]='a';
a3->name[1]='3';
a3->name[2]='\0';
a3->birth.day=13;
a3->birth.month=6;
a3->birth.year=2000;
a3->sex='M';
a3->next=a4;
a4->name[0]='a';
a4->name[1]='4';
a4->name[2]='\0';
a4->birth.day=13;
a4->birth.month=8;
a4->birth.year=1991;
a4->sex='W';
a4->next=NULL;
temp=findOldest(a1);
printf(temp->name);
}
struct student *compare(struct student *x,struct student *y)
{
if(x->birth.year>y->birth.year)
return x;
if(x->birth.year
return y;
else
if(x->birth.month>y->birth.month)
return x;
if(x->birth.month
return y;
else
if(x->birth.day>y->birth.day)
return x;
if(x->birth.day
return y;
else
return x;
}
struct student * findOldest(struct student * p)
{
struct student *temp=p;
while(p->next==NULL)
{
temp=compare(temp,p->next);
p=p->next;
}
return temp;
}
差不多这样吧 不足的你自己改改