#include
#include
#include"student.cpp"
#define NULL 0
int main(){
struct student h,a,b,c,d,*head,*p,*pp,*before,*temp;
a.num = 99101; a.score = 12;
b.num = 99103; b.score = 2;
c.num = 99107; c.score = 343;
d.num = 99107; d.score = 4;
head = &h;h.next=&a;a.next = &b;b.next=&c;c.next=&d;
p=head->next;
d.next = NULL ;
do{
printf("%ld %5.1f\n",p->num,p->score);
p=p->next;
}while(p!= NULL);
for(p=head;p->next!= NULL;p=p->next){
temp=p;
for(pp=p;pp->next!=NULL;pp=pp->next)
if(pp->next->score > temp->next->score)
temp= pp;
if(p->next==temp){
p->next = temp->next;
temp->next=temp->next->next;
p->next->next=temp;
}else{
before=temp->next->next;
temp->next->next=p->next->next;
p->next->next=before;
before=temp->next;
temp->next=p->next;
p->next=before;
}
}
printf("\n");
p=head->next;
do{
printf("%5.1f\n",p->score);
p=p->next;
}while(p!= NULL);
}
#include
struct student{
long num ;
float score;
struct student *next;
};